Каждая юридическая специализация имеет typedef this_type , который является тем же классом, что и сама специализация. Поскольку «основной» шаблон имеет все значения false , я решил использовать false в Typedef вместо имен параметров шаблона. Static_assert гарантирует, что все параметры шаблона являются false , и This_type действительно тот же тип. Код без жалоб, но GCC и MSVC дают ошибку «не могут быть дефолта». < /p>
Код: Выделить всё
#include
#include
template
class foo
{
static_assert(!(ISNUM || ISINT || std::numeric_limits::is_specialized || std::numeric_limits::is_integer));
typedef foo this_type;
// typedef foo this_type; ALWAYS WORKS
T v;
public:
foo (T iv): v (std::move (iv)) {}
foo (this_type const &) = default; // HERE
foo (this_type &&) = default; // ALSO HERE
void nominal_thing();
};
template
class foo
{
static_assert(std::numeric_limits::is_integer && !std::numeric_limits::is_specialized, "don't mess with constraints");
static_assert(!std::numeric_limits::is_integer, "this specialization is forbidden");
};
template
class foo
{
static_assert(std::numeric_limits::is_specialized && !std::numeric_limits::is_integer, "don't mess with constraints");
typedef foo this_type;
T v;
public:
foo (T iv): v (std::move (iv)) {}
foo (this_type const &) = default;
foo (this_type &&) = default;
void ratio_thing();
};
template
class foo
{
static_assert( std::numeric_limits::is_specialized
&& std::numeric_limits::is_integer,
"don't mess with constraints");
typedef foo this_type;
T v;
public:
foo (T iv): v (std::move (iv)) {}
foo (this_type const &) = default;
foo (this_type &&) = default;
void integer_thing();
};
using namespace std::string_literals;
int main()
{
foo fd {20} ;
foo fs {"a string"s} ;
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... -inconsist
Мобильная версия