我想在编译时检测给定类型是否具有库基础 TS v2 type_traits' is_detected_exact 的预增量运算符。 helper - 但是,看来我要么误解了这个helper,要么提供了错误的参数,以下代码无法编译:
#include <experimental/type_traits>
template<typename T>
using operator_plusplus_t = decltype(&T::operator++);
template<typename T>
using has_pre_increment = std::experimental::is_detected_exact<T&, operator_plusplus_t, T>;
struct incrementer
{
incrementer& operator++() { return *this; };
};
static_assert(has_pre_increment<incrementer>::value, "type does not have pre increment");
我得到的错误是这个(static_assert 失败):
<source>:14:15: error: static assertion failed: type does not have pre increment
static_assert(has_pre_increment<incrementer>::value, "type does not have pre increment");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Compiler returned: 1
我期望这段代码能够编译,因为“incrementer”结构有一个operator++方法,没有参数返回对其类型的引用...
也许您可以为我指明正确的方向,提前致谢!
最佳答案
您可以使用decltype(++std::declval<T>())
相反。
关于c++ - 使用 std::is_Detected_exact 检测运算符++签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53226919/