标签:pac pen ios cat ace ++ 必须 ati 函数返回
编译: g++ tuple.cpp -std=c++14#include <iostream>
#include <tuple>
using namespace std;
template<typename T, size_t N>
struct RTuple
{
static auto reverse(T& tup)
{
return move( tuple_cat( make_tuple(get<N-1>(tup)), RTuple<T,N-1>::reverse(tup)) );
}
};
template<typename T >
struct RTuple<T, 1>
{
static auto reverse(T& tup)
{
return move( make_tuple(get<0>(tup)) );
}
};
template<typename T>
struct RTuple<T,0>
{
static auto reverse(T& tup)
{
return move(tup);
}
};
int main(int argc, char* argv[])
{
auto t1 = make_tuple(1,2,3,4);
auto in1 = RTuple<decltype(t1),4>::reverse(t1);
cout<<get<0>(t1)<<",";
cout<<get<1>(t1)<<",";
cout<<get<2>(t1)<<",";
cout<<get<3>(t1)<<endl;
cout<<get<0>(in1)<<",";
cout<<get<1>(in1)<<",";
cout<<get<2>(in1)<<",";
cout<<get<3>(in1)<<endl;
tuple<> t2;
auto size = tuple_size<decltype(t2)>::value;
cout<<size<<endl;
//if ( size > 0 )
// cout<<get<0>(t2)<<endl;
auto in2 = RTuple<decltype(t2),0>::reverse(t2);
size = tuple_size<decltype(in2)>::value;
cout<<size<<endl;
//if ( size > 0 )
// cout<<get<0>(in2)<<endl;
return 0;
}
标签:pac pen ios cat ace ++ 必须 ati 函数返回
原文地址:https://blog.51cto.com/hakuyo/2419470