fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. template<typename T, class Derived>
  5. class FooBase {
  6. public:
  7. void foo(const std::vector<T> vec) {
  8. static_cast<Derived&>(*this).fooImpl(vec);
  9. }
  10. };
  11. template<typename T>
  12. class Foo : FooBase<T, Foo<T>> {
  13. public:
  14. void fooImpl(const std::vector<T> vec) {
  15. std::cout << "Normal foo";
  16. }
  17. };
  18.  
  19.  
  20. template
  21. class Foo<uint16_t>;
  22. template
  23. class Foo<uint32_t>;
  24. template
  25. class Foo<uint64_t>;
  26.  
  27. template <>
  28. class Foo<int16_t>: public FooBase<uint16_t, Foo<int16_t>>, public Foo<uint16_t> {
  29. public:
  30. using FooBase<uint16_t, Foo<int16_t>>::foo;
  31. void fooImpl(const std::vector<uint16_t> vec) {
  32. std::cout << "Special foo";
  33. Foo<uint16_t>::fooImpl(vec);
  34. }
  35. };
  36.  
  37. int main() {
  38. Foo<int16_t>().foo(std::vector<uint16_t>());
  39. return 0;
  40. }
Success #stdin #stdout 0s 4276KB
stdin
Standard input is empty
stdout
Special fooNormal foo