在这里,我注意到以下代码是在MSVC 19.27上编译的
template <typename T>
concept defined = true;
template <!defined T> // <=== !!!!!!!!
inline auto constexpr Get()
{
return 5;
}到底怎么回事?允许这种语法真的是个坏主意吗?
发布于 2021-04-20 16:12:48
你说得对;MSVC19.27和19.28 (VS16.9之前的版本)支持使用!进行概念否定的语法(compiler explorer中的cf)。
即使在C++20中不允许使用此语法,您也可以执行一些非常接近的操作
template<typename T>
concept defined = your_rule_on<T>;
template <typename T>
requires defined<T>
inline auto constexpr Get() { /* ... */ }
template <typename T>
requires(!defined<T>) // <=== !
inline auto constexpr Get() { /* ... */ }发布于 2020-08-16 22:13:17
不,当概念作为占位符或简明模板语法的一部分使用时,不允许将运算符应用于概念。如果您需要这样做,那么您需要创建一个新概念,或者使用requires子句将其拼写为长文本。
https://stackoverflow.com/questions/63435642
复制相似问题