Explicitly defaulting a templated constructor

Viewed 182

I tried to make default constructor = default; conditionally depending on class template argument's property using following technique:

#include <type_traits>
#include <utility>
#include <iostream>

#include <cstdlib>

template< typename T >
struct identity
{

};

template< typename T >
struct has_property
    : std::false_type
{

};

template< typename T >
struct S
{
    template< typename X = T,
              typename = std::enable_if_t< !has_property< X >::value > >
    S(identity< X > = {})
    { std::cout << __PRETTY_FUNCTION__ << std::endl; }

    template< typename X = T,
              typename = std::enable_if_t< has_property< X >::value > >
#if 0
    S() = default;
#else
    S()
    { std::cout << __PRETTY_FUNCTION__ << std::endl; }
#endif
};

struct A {};
struct B {};

template<>
struct has_property< B >
    : std::true_type
{

};

int main()
{
    S< A >{};
    S< B >{};
    return EXIT_SUCCESS;
}

But for #if 1 it gives an error:

main.cpp:32:11: error: only special member functions may be defaulted
    S() = default;
          ^

Is not template< ... > S() a declaration of a default constructor for S?

Can I implement such a dispatching using coming Concepts in future?

1 Answers
Related