1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
#define DECLARE_TUPLE_SERIALIZATION_FUNCTION(FUNC_NAME,BEG,SEP,END) \
namespace sjdfsjfyttsaihfah6755jsdf554433356sdf{ \
template <typename Tuple,std::size_t N> \
struct tuple_printer \
{ \
static void print(std::ostream& os,const Tuple& t) \
{ \
os<<std::get<std::tuple_size<Tuple>::value - N >(t)<<SEP; \
tuple_printer<Tuple,N-1>::print(os,t); \
} \
}; \
\
template <typename Tuple> \
struct tuple_printer<Tuple,1> \
{ \
static void print(std::ostream& os,const Tuple& t) \
{ \
os<<std::get<std::tuple_size<Tuple>::value-1>(t); \
} \
}; \
} \
template <typename Tuple> \
void FUNC_NAME(std::ostream& os,const Tuple& t) \
{ \
os<<BEG; \
sjdfsjfyttsaihfah6755jsdf554433356sdf::tuple_printer<Tuple,std::tuple_size<Tuple>::value>::print(os,t); \
os<<END; \
}
DECLARE_TUPLE_SERIALIZATION_FUNCTION(serialize_tuple,"<"," , ",">") //specify the function name, separator etc.
int main()
{
int i=10;
auto a = make_tuple(3,"lala",i,'c');
auto b = make_tuple(3,"lala");
serialize_tuple(std::cout,a);
}
|