Dukales

http://stackoverflow.com/questions/16376557

May 4th, 2013
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. #include <type_traits>
  2. #include <utility>
  3.  
  4. #include <list>
  5. #include <vector>
  6. #include <deque>
  7.  
  8. struct F
  9. {
  10.         using V = std::vector< float >;
  11.         using L = std::list< double >;
  12.         using D = std::deque< long double >;
  13.         template<
  14.                 typename T0, typename = typename std::enable_if< std::is_same< typename std::decay< T0 >::type, V >::value >::type,
  15.                 typename T1, typename = typename std::enable_if< std::is_same< typename std::decay< T1 >::type, L >::value >::type,
  16.                 typename T2, typename = typename std::enable_if< std::is_same< typename std::decay< T2 >::type, D >::value >::type
  17.         >
  18.         constexpr
  19.         F(T0 && _v,
  20.           T1 && _l,
  21.           T2 && _d)
  22.                 : v_(std::forward< T0 >(_v))
  23.                 , l_(std::forward< T1 >(_l))
  24.                 , d_(std::forward< T2 >(_d))
  25.         { ; }
  26.         private :
  27.         V const v_;
  28.         L const l_;
  29.         D const d_;
  30. };
  31.  
  32. int main()
  33. {
  34.         using V = typename F::V;
  35.         using L = typename F::L;
  36.         using D = typename F::D;
  37.         V v;
  38.         V const cv;
  39.         L l;
  40.         L const cl;
  41.         D d;
  42.         D const cd;
  43.         F(v, l, d);
  44.         F(cv, cl, cd);
  45.         F(V{1.0f, 2.0f}, L{3.0, 4.0}, D{5.0L, 6.0L});
  46.         // most interesting are below
  47.         F(v, l, cd);
  48.         F(v, cl, d);
  49.         F(cv, l, d);
  50.         F(v, cl, cd);
  51.         F(cv, cl, d);
  52.         F(cv, l, cd);
  53.         // ... I know you know how to continue
  54.         return 0;
  55. }
Add Comment
Please, Sign In to add comment