mizonokuchi

comparing a tuple with values

Sep 19th, 2012
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <tuple>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. template <int i, typename Tuple, typename T0>
  7. bool myequal(Tuple& t, T0 const & head){
  8.   if(get<i>(t) == head)
  9.     return true;
  10.   else
  11.     return false;
  12. }
  13.  
  14. template <int i, typename Tuple, typename T0, typename ... Types>
  15. bool myequal(Tuple& t, T0 const & head, Types ... tail){
  16.   if(get<i>(t) == head && myequal<i+1, Tuple, Types ...>(t, tail...))
  17.     return true;
  18.   else
  19.     return false;
  20. }
  21.  
  22. main(){
  23.   tuple<int, char> t(10, 'a');
  24.  
  25.   cout << myequal<0, decltype(t), int, char>(t, 10, 'a') << endl;
  26.   cout << myequal<0, decltype(t), int, char>(t, 11, 'a') << endl;
  27.   cout << myequal<0, decltype(t), int, char>(t, 11, 'b') << endl;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment