Skip to content

Instantly share code, notes, and snippets.

@tyanmahou
Last active December 27, 2017 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tyanmahou/3191562809de421cded4f40e65aaf5a1 to your computer and use it in GitHub Desktop.
Save tyanmahou/3191562809de421cded4f40e65aaf5a1 to your computer and use it in GitHub Desktop.
tupleのヘルパーメタ関数
#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