小编Bil*_*ill的帖子

为什么 std::derived_from 概念是通过添加 cv 限定符的附加可转换性测试来实现的?

在 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)
  1. 为什么要求__is_base_of(_Base, _Derived)不够?
  2. const volatile测试中需要用到什么?

c++ libstdc++ c++-concepts c++20

18
推荐指数
2
解决办法
679
查看次数

C ++ is_member_pointer实现

在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++ c++11

5
推荐指数
3
解决办法
225
查看次数

C ++析构函数返回类型

析构函数是一个特殊的成员函数,不带任何参数且没有返回类型:几乎所有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 ++标准对此的看法。

c++ destructor decltype language-lawyer c++11

5
推荐指数
1
解决办法
492
查看次数

c++ std 库实现者在为 remove_cvref 模板添加特化时警告未定义行为的关注点是什么?

在此链接中,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 库实现者关心的是什么?

c++ c++20

0
推荐指数
1
解决办法
81
查看次数