在 GCC C++20 概念库中,它有
template<typename _Derived, typename _Base>
concept derived_from = __is_base_of(_Base, _Derived)
&& is_convertible_v<const volatile _Derived*, const volatile _Base*>;
Run Code Online (Sandbox Code Playgroud)
__is_base_of(_Base, _Derived)不够?const volatile测试中需要用到什么?在c ++ std库中,is_member_pointer实现为
template<typename _Tp>
struct __is_member_pointer_helper
: public false_type { };
template<typename _Tp, typename _Cp>
struct __is_member_pointer_helper<_Tp _Cp::*>
: public true_type { };
/// is_member_pointer
template<typename _Tp>
struct is_member_pointer
: public __is_member_pointer_helper<typename remove_cv<_Tp>::type>::type
{ };
Run Code Online (Sandbox Code Playgroud)
有人可以解释_Cp的推导方式吗?它像魔术一样工作。
析构函数是一个特殊的成员函数,不带任何参数且没有返回类型:几乎所有c ++书籍都讲述了这一点。但是,在libstd ++库中,它使用以下内容测试类型是否可破坏,
struct __do_is_destructible_impl
{
template<typename _Tp, typename _U = decltype(declval<_Tp&>().~_Tp())>
static true_type __test(int);
template<typename>
static false_type __test(...);
};
Run Code Online (Sandbox Code Playgroud)
Gnu g ++将显示_U且typeid为void,因此,析构函数是否返回类型?专家请解释一下c ++标准对此的看法。
在此链接中,https://en.cppreference.com/w/cpp/types/remove_cvref,它指出
template< class T >
struct remove_cvref;
Run Code Online (Sandbox Code Playgroud)
如果类型 T 是引用类型,则提供成员 typedef type,它是 T 引用的类型,并删除了其最顶层的 cv 限定符。否则,类型是 T 并删除其最顶层的 cv 限定符。
添加专业化的程序的行为
remove_cvref是未定义的。
在这种情况下,c++ std 库实现者关心的是什么?