-, . registrar , . , , .
, Foo a, b c main:
template<typename T> class Foo
{
public:
Foo() { (void)&RegistrarWrapper<Foo<T>>::registrar; }
};
, . , , :
template<class T> constexpr std::size_t register_class()
{
(void)&RegistrarWrapper<T>::registrar;
return 1;
}
template<typename T> class Foo
{
static char reg[register_class<Foo<T>>()];
};
- (. ).
Clang 3.7.0, GCC 5.2.0 Visual ++ 2015, . constexpr, ++ 14. , ++ 11, .
, , , __reg_ptr , -. N4527:
14.7.1p2:
[...] ( ) , , .
constexpr, ( ) , odr ( registrar), .
14.7.1p1:
[...] , , - , -, , [...]
, . , .
, constexpr. CWG 1581, , , , , constexpr . ( ...), .
: Foo , :
template class Foo<int>;
template class Foo<bool>;
template class Foo<std::string>;
int main()
{
for(auto&& data : test_vector()) {
std::cout << data.name() << std::endl;
}
}
14.7.2p8:
, ( ) [...]
, , , , , GCC __reg_ptr. ([14.7p5.1]), . , .