fmt里判断是否为reference_wrapper

参考:

一窥模板的替换和匹配方式:偏特化的参数比泛化版本的还要多:判断是不是std::pair<,>。-CSDN博客

cpp 复制代码
C:\work\hchx\HchxKernel\PublicAPI\fmt\args.h

template <typename T> struct is_reference_wrapper : std::false_type {};
template <typename T>
struct is_reference_wrapper<std::reference_wrapper<T>> : std::true_type {};

一个引用的地方:

cpp 复制代码
template <typename T>
  using stored_type = conditional_t<detail::is_string<T>::value &&
                                        !has_formatter<T, Context>::value &&
                                        !detail::is_reference_wrapper<T>::value,
                                    std::basic_string<char_type>, T>;

reference_wrapper的定义

cpp 复制代码
template<class _Ty>
	class reference_wrapper
		: public _Weak_types<_Ty>::type
{	// stand-in for an assignable reference
public:
	static_assert(is_object_v<_Ty> || is_function_v<_Ty>,
		"reference_wrapper<T> requires T to be an object type or a function type.");

	using type = _Ty;

	template<class _Uty,
		enable_if_t<conjunction_v<
			negation<is_same<remove_cv_t<remove_reference_t<_Uty>>, reference_wrapper>>,
			_Refwrap_has_ctor_from<_Ty, _Uty>>, int> = 0>
		reference_wrapper(_Uty&& _Val)
			_NOEXCEPT_COND(_NOEXCEPT_OPER(_Refwrap_ctor_fun<_Ty>(_STD declval<_Uty>())))
			{	// construct
			_Ty& _Ref = _STD forward<_Uty>(_Val);
			_Ptr = _STD addressof(_Ref);
			}

	operator _Ty&() const noexcept
		{	// return reference
		return (*_Ptr);
		}

	_NODISCARD _Ty& get() const noexcept
		{	// return reference
		return (*_Ptr);
		}

	template<class... _Types>
		auto operator()(_Types&&... _Args) const
		-> decltype(_STD invoke(get(), _STD forward<_Types>(_Args)...))
		{	// invoke object/function
		return (_STD invoke(get(), _STD forward<_Types>(_Args)...));
		}

private:
	_Ty * _Ptr;
	}
相关推荐
C++ 老炮儿的技术栈3 分钟前
VS2015 + Qt 实现图形化Hello World(详细步骤)
c语言·开发语言·c++·windows·qt
Once_day10 分钟前
C++之《Effective C++》读书总结(4)
c语言·c++·effective c++
柯一梦14 分钟前
STL2---深入探索vector的实现
c++
MSTcheng.22 分钟前
【C++】C++11新特性(二)
java·开发语言·c++·c++11
愚者游世24 分钟前
Delegating Constructor(委托构造函数)各版本异同
开发语言·c++·程序人生·面试·改行学it
小镇敲码人26 分钟前
探索华为CANN框架中的ACL仓库
c++·python·华为·acl·cann
liu****1 小时前
2.深入浅出理解虚拟化与容器化(含Docker实操全解析)
运维·c++·docker·容器·虚拟化技术
A9better1 小时前
C++——不一样的I/O工具与名称空间
开发语言·c++·学习
王老师青少年编程2 小时前
2024年信奥赛C++提高组csp-s初赛真题及答案解析(阅读程序第2题)
c++·题解·真题·初赛·信奥赛·csp-s·提高组
MSTcheng.2 小时前
【C++】C++11新特性(三)
开发语言·c++·c++11