Last active
December 27, 2017 17:35
-
-
Save tyanmahou/3191562809de421cded4f40e65aaf5a1 to your computer and use it in GitHub Desktop.
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> | |
///<summary> | |
//タプル型の結合 | |
///<summary> | |
template<class Type1, class Type2> | |
struct TupleCombine | |
{ | |
using type = std::tuple<Type1, Type2>; | |
}; | |
template<class Type, class... Args> | |
struct TupleCombine<Type, std::tuple<Args...>> | |
{ | |
using type = std::tuple<Type, Args...>; | |
}; | |
template<class Type, class... Args> | |
struct TupleCombine<std::tuple<Args...>, Type> | |
{ | |
using type = std::tuple<Args..., Type>; | |
}; | |
template<class ...Args1, class... Args2> | |
struct TupleCombine<std::tuple<Args1...>, std::tuple<Args2...>> | |
{ | |
using type = std::tuple<Args1..., Args2...>; | |
}; | |
///<summary> | |
///ある型をtuple型として取得する | |
///<summary> | |
template<class Type, size_t N = 1> | |
struct AsTuple | |
{ | |
using type = typename TupleCombine< | |
Type, | |
typename AsTuple<Type, N - 1>::type | |
>::type; | |
}; | |
template<class Type> | |
struct AsTuple<Type, 1> | |
{ | |
using type = std::tuple<Type>; | |
}; | |
template<class Type> | |
struct AsTuple<Type, 0> | |
{}; | |
template<class Type, size_t N = 1> | |
using AsTuple_t = typename AsTuple<Type, N>::type; | |
/* | |
int main() | |
{ | |
//std::tuple<int> | |
AsTuple_t<int> a(1); | |
//std::tuple<int,int,int> | |
AsTuple_t<int, 3> b(1,2,3); | |
return 0; | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment