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;
	}
相关推荐
念恒123062 小时前
继承(下) (Inheritance)
c++
H Journey3 小时前
C++之 CMake、CMakeLists.txt、Makefile
开发语言·c++·makefile·cmake
研究点啥好呢7 小时前
Github热门项目推荐 | 创建你的像素风格!
c++·python·node.js·github·开源软件
_dindong7 小时前
cf1091div2 C.Grid Covering(数论)
c++·算法
沫璃染墨7 小时前
C++ string 从入门到精通:构造、迭代器、容量接口全解析
c语言·开发语言·c++
6Hzlia8 小时前
【Hot 100 刷题计划】 LeetCode 17. 电话号码的字母组合 | C++ 回溯算法经典模板
c++·算法·leetcode
计算机安禾8 小时前
【数据结构与算法】第36篇:排序大总结:稳定性、时间复杂度与适用场景
c语言·数据结构·c++·算法·链表·线性回归·visual studio
unicrom_深圳市由你创科技8 小时前
做虚拟示波器这种实时波形显示的上位机,用什么语言?
c++·python·c#
无限进步_8 小时前
【C++】电话号码的字母组合:从有限处理到通用解法
开发语言·c++·ide·windows·git·github·visual studio
C++ 老炮儿的技术栈9 小时前
GCC编译时无法向/tmp 目录写入临时汇编文件,因为设备空间不足,解决
linux·运维·开发语言·汇编·c++·git·qt