[英]How can I require (in a C++20 concept) that a type T be a reference to a floating point type?
In the C++20 concepts library, there is std::floating_point<T>
which "is satisfied if and only if T is a floating-point type" ( ref ).在 C++20 概念库中,有
std::floating_point<T>
,“当且仅当 T 是浮点类型时才满足”( ref )。 But I need T
to be a reference to a floating-point type.但我需要
T
成为对浮点类型的引用。 What is a requires
clause that expresses this?表达这一点的
requires
子句是什么?
As Davis said in the comments, just use type traits:正如戴维斯在评论中所说,只需使用类型特征:
template <typename T>
concept is_floating_point_reference =
std::is_reference_v<T> &&
std::floating_point<std::remove_reference_t<T>>;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.