fork download
  1. #include <iostream>
  2. #if 0
  3. # define CONSTEXPR constexpr
  4. #else
  5. # define CONSTEXPR
  6. #endif
  7.  
  8. template <typename T> struct Foo {
  9. typedef T Type;
  10. static const CONSTEXPR std::size_t k_Dim = sizeof(T);
  11. };
  12.  
  13. template <typename I, typename O> struct Bar {
  14. static const CONSTEXPR std::size_t k_IDim = I::k_Dim;
  15. static const CONSTEXPR std::size_t k_ODim = O::k_Dim;
  16. };
  17.  
  18. // declare
  19. extern template struct Bar<Foo<int>, Foo<double> >;
  20.  
  21. // ----< of .h
  22.  
  23. // define in one TU
  24. template struct Bar<Foo<int>, Foo<double> >;
  25.  
  26. // use, in another TU
  27. int main ()
  28. {
  29. typedef Bar<Foo<int>, Foo<double> > Type;
  30. std::cout << Type::k_IDim << " -- " << Type::k_ODim << "\n";
  31. }
  32.  
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
4 -- 8