且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用 c++20 检查 type 是否具有某些值类型和关键字 value_type 本身

更新时间:2023-10-06 08:20:46

  1. 您发布的代码中有几个拼写错误.清理完毕,以下内容符合您的要求:

template<typename T, typename U, typename Tout>
requires std::is_integral_v<typename T::value_type>
      && std::is_floating_point_v<typename U::value_type>
      && std::is_floating_point_v<typename Tout::value_type>
class test {
public:
    test()=default;
};

  1. 这是一个很大的问题.也许其他人可以填补这个空白.
  2. 编译器生成的错误消息(此处为 g++ 10.2)似乎很清楚:

int main() {
  test<int, int, int> t;
}

main.cpp: In function 'int main()':
main.cpp:16:21: error: template constraint failure for 'template<class T, class U, class Tout>  requires (is_integral_v<typename T::value_type>) && (is_floating_point_v<typename U::value_type>) && (is_floating_point_v<typename Tout::value_type>) class test'
   16 |   test<int, int, int> t;
      |                     ^
main.cpp:16:21: note: constraints not satisfied