我这样写了一个is_incrementable
特质:
#include <type_traits>
template <typename T, typename = void>
struct is_incrementable : std::false_type {};
template <typename T>
struct is_incrementable<T, std::void_t<decltype(++std::declval<T&>())>>
: std::true_type {};
template <typename T>
constexpr bool is_incrementable_v = is_incrementable<T>::value;
当我使用bool
并将其应用于-std=c++17
时,它返回true
:
// This compiles
static_assert(is_incrementable_v<bool>, "");
但是在c ++ 17下不允许递增bool
。确实,如果我尝试这样做,则会出现错误:
bool b = false;
++b;
导致:
error: ISO C++17 does not allow incrementing expression of type bool [-Wincrement-bool]
当编译器显然不允许bool
时,为什么SFINAE报告webpack.config.js
是可递增的?
编译器资源管理器:https://godbolt.org/g/DDFYBf