我想在编译时检测给定类型是否具有带有库基础 TS v2 type_traits' is_detected_exact帮助器的预增量运算符- 但是,似乎我误解了这个帮助器或者我提供了错误的参数,下面的代码没有编译:
#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++ 方法,没有参数返回对其类型的引用......
也许你可以指出我正确的方向,在此先感谢!