Created
September 27, 2013 16:37
-
-
Save Fuyutsubaki/6731367 to your computer and use it in GitHub Desktop.
for each of tuple
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include<tuple> | |
namespace deteil{ | |
template<class Tuple,class Visitor> | |
class _tuple_foreach | |
{ | |
public: | |
void operator()(Tuple & tuple, Visitor& visitor) | |
{ | |
loop<0>(visitor,tuple); | |
} | |
private: | |
static const size_t N = std::tuple_size<Tuple>::value; | |
template<size_t i> | |
void loop(Visitor &visitor, Tuple & tuple) | |
{ | |
visitor(std::get<i>(tuple)); | |
loop<i + 1>(visitor,tuple); | |
} | |
template<> | |
void loop<N>(Visitor& visitor, Tuple & tuple){} | |
}; | |
} | |
template<class Tuple,class Visitor> | |
Visitor& tuple_foreach(Tuple&tuple, Visitor&visitor) | |
{ | |
deteil::_tuple_foreach<Tuple, Visitor> x; | |
x(tuple,visitor); | |
return visitor; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment