fpelliccioni

To Howard First Issue

May 11th, 2012
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <initializer_list>
  3. #include <map>
  4. #include <string>
  5. #include <utility>
  6.  
  7. template <typename T>
  8. struct my_vector
  9. {
  10.   my_vector( )
  11.   {
  12.     std::cout << "my_vector - ctor" << std::endl;
  13.   }
  14.  
  15.   my_vector( std::initializer_list<T> init_list )
  16.   {
  17.     std::cout << "my_vector - init list ctor" << std::endl;
  18.   }
  19.  
  20.   my_vector( my_vector const& lvalue )
  21.   {
  22.     std::cout << "my_vector - copy ctor" << std::endl;
  23.   }
  24.  
  25.   my_vector& operator=( my_vector const& lvalue )
  26.   {
  27.     std::cout << "my_vector - copy assignment op" << std::endl;
  28.   }
  29.  
  30.   my_vector( my_vector && other )
  31.   {
  32.     std::cout << "my_vector - move ctor" << std::endl;
  33.   }
  34.  
  35.   my_vector& operator=( my_vector&& rvalue )
  36.   {
  37.     std::cout << "my_vector - move assignment op" << std::endl;
  38.   }
  39.  
  40.   ~my_vector()
  41.   {
  42.     std::cout << "my_vector dtor" << std::endl;
  43.   }
  44. };
  45.  
  46. template <typename T1, typename T2>
  47. struct my_pair
  48. {
  49.   T1 t1_;
  50.   T2 t2_;
  51.  
  52.   my_pair( T1 const& t1, T2 const& t2 )
  53.     : t1_( t1 ), t2_( t2 )
  54.   {
  55.     std::cout << "my_pair ctor" << std::endl;
  56.   }
  57.  
  58.   template<typename U1, typename U2>
  59.   my_pair( U1&& u1, U2&& u2 )
  60.     : t1_( std::forward<U1>(u1) ), t2_( std::forward<U2>(u2) )
  61.   {
  62.     std::cout << "my_pair ctor - && - template" << std::endl;
  63.   }
  64.  
  65.   my_pair( my_pair const& other )
  66.     : t1_(other.t1_), t2_(other.t2_)
  67.   {
  68.     std::cout << "my_pair copy ctor" << std::endl;
  69.   }
  70.  
  71.   my_pair( my_pair && other )
  72.     : t1_( std::move(other.t1_)), t2_( std::move(other.t2_))
  73.   {
  74.     std::cout << "my_pair move ctor" << std::endl;
  75.   }
  76.  
  77.   ~my_pair()
  78.   {
  79.     std::cout << "my_pair dtor" << std::endl;
  80.   }
  81.  
  82.  
  83. #ifdef MY_PAIR_NEW_CTOR
  84.   my_pair( T1 && t1, T2 && t2 )
  85.     : t1_( std::forward<T1>(t1) ), t2_( std::forward<T2>(t2) )
  86.   {
  87.     std::cout << "my_pair ctor - &&" << std::endl;
  88.   }
  89. #endif
  90.  
  91.  
  92.  
  93.   //Not used
  94.   template < typename U1, typename U2 >
  95.   my_pair( const my_pair<U1,U2>& p );
  96.  
  97.   template < typename U1, typename U2 >
  98.   my_pair( my_pair<U1,U2>&& p );
  99.  
  100. };
  101.  
  102.  
  103. using namespace std;
  104.  
  105.  
  106. typedef std::pair<std::string, my_vector<string> > std_pair_type;
  107. typedef my_pair<std::string, my_vector<string> > my_pair_type;
  108.  
  109. int main( /* int argc, char* argv[] */ )
  110. {
  111.   std_pair_type p1 ("list", my_vector<string>() );
  112.   cout << "-------------------------------------\n";
  113.   std_pair_type p2 ("list",  { "val1", "val2", "val3" }  );
  114.   cout << "-------------------------------------\n";
  115.  
  116.  
  117.  
  118.  
  119.   my_pair_type p3 ("list", my_vector<string>() );
  120.   cout << "-------------------------------------\n";
  121.   my_pair_type p4 ("list", { "val1", "val2", "val3" } );
  122.   cout << "-------------------------------------\n";
  123.  
  124.  
  125.  
  126.   return 0;
  127. }
Advertisement
Add Comment
Please, Sign In to add comment