【发布时间】:2021-07-12 05:51:45
【问题描述】:
我们如何将这个问题link中的要求转换为概念
我尝试了以下方法:
template< typename U, typename Tin, typename Tout>
concept MyConditions =
(
U::value_type
&& Tin::value_type
&& Tout::value_type
&& std::is_floating_point_v<typename Tin::value_type>
&& std::is_integral_v<typename U::value_type>
&& std::is_floating_point_v<typename Tout::value_type>
);
这个概念现在应用于我的一个成员函数:
class test_concept
{
template< typename U, typename Tin, typename Tout>
requires MyConditions <U, Tin, Tout>
static void test_routine(const U&, const Tin&, Tout& );
}
测试时:
std::vector<double> test{ };
std::vector<int> testi{ };
std::vector<double> test2{ };
test_concept::test_routine(testi, test, test2);
使用 clang 我收到错误消息,指出未找到匹配项,并附注:
注意:因为替换的约束表达式格式不正确:缺失 'typename' 之前 依赖类型名称 'vector
::value_type' U::value_type
【问题讨论】:
标签: c++ templates c++20 c++-concepts