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