1

So, here is a snippet of the code that I believe is enough to illustrate the problem, the nested templated structs:

namespace util
{
    // Adapted from https://stackoverflow.com/a/28352296/7332177:
    template<typename T, typename... Args>
    struct __constructible_from
    {
    private:
        template<typename S>
        static S arg();

        template<typename U>
        static std::true_type constructible_test(U *, decltype(U(arg<Args>()...)) * = 0);
        static std::false_type constructible_test(...);

    public:
        using result = decltype(constructible_test(static_cast<T *>(nullptr)));
    };

    template<typename T>
    struct constructible
    {
        template<typename... Args>
        struct from : __constructible_from<T, Args...>::result { };
    };
}

how I want to use it:

template<typename T, typename... Args>
void check (void)
{
    if constexpr (util::constructible<T>::from<Args...>::value)
        std::cout << "TRUE!" << std::endl;
    else
        std::cout << "FALSE!" << std::endl;
}

struct A { };

int main (void)
{
    check<A>();
}

and how I currently need to use it:

template<typename T, typename... Args>
void check (void)
{
    if constexpr (util::constructible<T>::template from<Args...>::value)
        std::cout << "TRUE!" << std::endl;
    else
        std::cout << "FALSE!" << std::endl;
}

struct A { };

int main (void)
{
    check<A>();
}

My question is if there is any way to declare the nested "from" struct without having to append the "template" keyword in the if statement?

PS: This is only a problem with GCC, MSVC compiles the code just fine, but I'm assuming that that's because MSVC compiles even "ill-formed" c++ code.

Lengors
  • 63
  • 1
  • 5
  • To avoid the use of the `template` before `from`, I suppose you could directly use `__constructible_from` – max66 Jan 27 '20 at 20:45

0 Answers0