i'm wrestling visual studio 2017 (compiling using /std:c++latest
if that's help).
the code in question selects struct specialization based on result of templated constexpr
function. gcc , clang have no trouble compiling it.
here's mcve:
#include <type_traits> struct { enum { test_trait = true }; }; template<typename t> constexpr int choose() { return t::test_trait; } template<typename t, typename enable=void> struct chosen; template<typename t> struct chosen<t, std::enable_if_t<choose<t>() == 1>> {}; void foo() { // works constexpr int chosen = choose<a>(); static_assert(chosen == 1, ""); // resolves undefined struct. using chosen_t = chosen<a>; chosen_t x; (void)x; }
choose()
fair bit more complex in codebase, static_assert
still compiles, , checks fine.
i kinda assumed if static_assert
compiles, there no reason enable_if
not able magic. wrong? guess "maybe" t
not technically dependant type of enable_if
... if case, i'd expect gcc , clang slap wrist.
i can around wrapping result of choose()
in std::integral_constant
, so:
template<typename t> struct chooser : public std::integral_constant<int, choose<t>()> {}; template<typename t> struct chosen<t, std::enable_if_t<chooser<t>::value>> {};
but i'd rather not have jump through hoop.
should template resolution able resolve way expect? i'm worried code wrong, , gcc , clang being lenient on me.
Comments
Post a Comment