fork(13) download
  1. #include <type_traits>
  2.  
  3. template<typename T>
  4. struct extract_value_type
  5. {
  6. typedef T value_type;
  7. };
  8.  
  9. template<template<typename> class X, typename T>
  10. struct extract_value_type <X<T>> //specialization
  11. {
  12. typedef T value_type;
  13. };
  14.  
  15. /////////////////////////////
  16.  
  17. struct X {};
  18. template <typename T> struct Y {};
  19.  
  20. template<typename C, typename T>
  21. void test()
  22. {
  23. typedef typename extract_value_type<C>::value_type value_type;
  24. static_assert(std::is_same<value_type, T>::value, "mismatched");
  25. }
  26.  
  27. int main()
  28. {
  29. test<X,X>();
  30. test<Y<X>,X>();
  31. }
Success #stdin #stdout 0s 2880KB
stdin
Standard input is empty
stdout
Standard output is empty