Why can't this enable_if function template be specialized in VS2017?

后端 未结 2 714
无人及你
无人及你 2021-02-09 10:38

The following compiled with VS2015, but fails in VS2017 with the below errors. Was the code doing something non standard that has been fixed in VS2017, or should VS2017 compile

2条回答
  •  攒了一身酷
    2021-02-09 11:27

    This might be a bug in Visual Studio. A possible workaround could be using template specialization instead of overloading:

    template 
    struct is_flags { constexpr static bool value = false; };
    
    template <>
    struct is_flags { constexpr static bool value = true; };
    
    template std::enable_if_t::value, std::underlying_type_t> operator | (E lhs, E rhs)
    {
        return ToUnderlying(lhs) | ToUnderlying(rhs);
    }
    

提交回复
热议问题