Advertisement
NLinker

Small C++ exercise

Jul 15th, 2014
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include <type_traits>
  2. #include <algorithm>
  3.  
  4. //  if they are on two different types, function returs false.
  5. template< typename T, typename U, typename F, typename G >
  6. typename std::enable_if< !std::is_same<T,U>::value, bool >::type
  7. check( const my_vector<T,F>& , const my_vector<U,G>& ) { return false ; }
  8.  
  9. // same type and on the same functor ...
  10. template< typename T, typename U, typename F, typename G >
  11. typename std::enable_if< std::is_same<T,U>::value && std::is_same<F,G>::value, bool >::type
  12. check( const my_vector<T,F>& a, const my_vector<U,G>& b )
  13. {
  14.     if( a.size() == b.size() ) return std::equal( a.begin(), a.end(), b.begin() ) ;
  15.     else return false ;
  16. }
  17.  
  18. // on same type but different functors, create a new my_vector ...
  19. template< typename T, typename U, typename F, typename G >
  20. typename std::enable_if< std::is_same<T,U>::value && !std::is_same<F,G>::value, bool >::type
  21. check( const my_vector<T,F>& a, const my_vector<U,G>& b )
  22. { return a.size() == b.size() ? check( a, my_vector<T,F>(b) ) : false ; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement