void_t fails on Visual Studio 2015

孤人 提交于 2019-12-03 04:57:46
apardoe

This does look like a SFINAE issue in VC++. Using a dependent decltype in the template argument of partial specialization of a class template isn't yet supported. It should work in VS 2015 Update 1.

Walter E. Brown at CppCon 2014 also mentioned the following factorization which allows to replace try_assign with arbitrary condition.

#include <type_traits>
#include <utility>

template<class T>
using try_assign = decltype(std::declval<T&>() = std::declval <T const &>());

template<class T, template<class> class Op, class = void>
struct is_valid : std::false_type { };

template<class T, template<class> class Op>
struct is_valid<T, Op, std::void_t<Op<T>>> : std::true_type { };

template<class T>
using is_copy_assignable = is_valid<T, try_assign>;

int main()
{
    static_assert(is_copy_assignable<int>::value, "fail");
    return 0;
}

This factorization compiles OK with VS 2015. Now remove is_copy_assignable and substitute into is_valid. You end up with the code you presented and which doesn't compile (VS 2015).

This suggests there's a bug in VS 2015 and it's not related to CWG 1558. In CWG issue the standard was unclear whether unused arguments in alias template specializations could result in substitution failure or are simply ignored.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!