fork download
  1. #include <iostream>
  2. #include <type_traits>
  3. #include <typeinfo>
  4.  
  5. using namespace std;
  6.  
  7. template <typename A,typename B>
  8. struct basic_storage
  9. {
  10. using a_type = A;
  11. using b_type = B;
  12. static constexpr bool value = b_type::value;
  13. };
  14.  
  15.  
  16. template
  17. <
  18. template <typename, typename>
  19. class storage_t,
  20. typename T,
  21. typename is_allocated
  22. >
  23. class Buffer : public storage_t<T, is_allocated> {
  24.  
  25. public:
  26. using storage_type = storage_t<T, is_allocated>;
  27. };
  28.  
  29. template
  30. <
  31. template <typename, typename>
  32. class storage_t,
  33. typename T /*= storage::UnknownType*/,
  34. typename is_allocated = std::false_type
  35. >
  36. class Example_Buffer
  37. : public Buffer<storage_t, T, is_allocated> {
  38. public:
  39. constexpr Example_Buffer(
  40. /*typename storage_t<T, is_allocated>::iterator it*/) {
  41.  
  42. //using the members with the injected class name..
  43. using b_type = typename Example_Buffer::b_type;
  44.  
  45. // or directly using injected class name..
  46. std::cout << typeid(typename Example_Buffer::a_type).name() << std::endl;
  47. std::cout << Example_Buffer::value << std::endl;
  48.  
  49. // using storage_type defined in Buffer<...>
  50. using storage_type = typename Example_Buffer::storage_type;
  51.  
  52. std::cout << typeid(typename storage_type::a_type).name() << std::endl;
  53. std::cout << storage_type::b_type::value << std::endl;
  54. std::cout << storage_type::value << std::endl;
  55.  
  56. }
  57. };
  58.  
  59.  
  60. int main() {
  61. Example_Buffer<basic_storage,int,std::true_type>{};
  62. return 0;
  63. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
i
1
i
1
1