2
我碰到的這個的一天。MSVC - 成員檢測與void_t不能正常工作
#include <iostream>
#include <type_traits>
using namespace std;
template<typename... Ts> struct make_void { typedef void type; };
template<typename... Ts> using void_t = typename make_void<Ts...>::type;
template <class, class = void>
struct is_func_chrend_ : std::false_type {};
template <class T>
struct is_func_chrend_<T, ::void_t<decltype(std::declval<T>().NextTile())>> : std::true_type {};
template <class = void, class = void>
struct is_addable : std::false_type {};
template <class T>
struct is_addable<T, ::void_t<decltype(std::declval<T>() + std::declval<T>())>> : std::true_type {};
int main() {
cout << is_addable<int>::value << endl;
return 0;
}
顯示0,如果在鐺或GCC編譯MSVC,1編譯時。 完全刪除is_func_chrend_
使得is_addable
再次正常工作。
權宜之計void_t
僅用於C++ 11兼容的編譯器。
沒有調查你的代碼,但VS沒有完全實現表達式SFINAE – bolov
試試這個http://stackoverflow.com/q/35669239/3953764 –
你可能需要絕對最新的MSVC才能工作。我用VS2015 SP3獲得'1'。 –