我想在编译时检测给定类型是否具有带库基础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 ++方法,并且不带参数返回对其类型的引用,所以我一直希望这段代码能够被编译。
也许,您可以为我指明正确的方向,谢谢!!