c++ - Calling constexpr function in enable_if_t -
consider following example:
#include <type_traits> template <typename t, typename enable = void> struct a; template <typename t> constexpr bool f() { return true; } template <typename t> struct a<t, std::enable_if_t<f<t>()>> {}; int main() { a<int> f; }
it compiles fine clang , gcc msvc gives following error:
13 : <source>(13): error c2079: 'f' uses undefined struct 'a<int,void>'
is bug in msvc or code , how can fix it?
i'm msvc bug.
some testing reveals msvc refuses match specialized template, providing definition , static_assert
in primary template can used verify this.
after digging this popped up, , apparently using types in sfinae constructs works, somehow not functions.
the end result this workaround, annoying bearable
#include <type_traits> template <typename t, typename = void> struct a; template <typename t> struct f { constexpr operator bool() {return true;} }; template <typename t> struct a<t, std::enable_if_t<(f<t>())>> {}; // note braces int main() { a<int> a; }
Comments
Post a Comment