2 Star 4 Fork 0

wkh / generic

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
TypeList.hpp 2.18 KB
一键复制 编辑 原始数据 按行查看 历史
wkh 提交于 2021-11-05 15:07 . first commit
/*
* @Author: wkh
* @Date: 2021-11-03 22:38:05
* @LastEditTime: 2021-11-05 14:55:25
* @LastEditors: wkh
* @Description:
* @FilePath: /GP/Typelist/TypeList.hpp
*
*/
#pragma once
#include <iostream>
#include <tuple>
namespace TypeList
{
template<typename... Args>
class TypeList{};
template<typename List>
class Front{};
template<typename Head,typename ...Tail>
class Front<TypeList<Head,Tail...>>
{
public:
using type = Head;
};
template<typename T>
using front = typename Front<T>::type;
template<typename List>
class Tail{};
template<typename... Head,typename T>
class Tail<TypeList<Head...,T>>
{
public:
using type = T;
};
template<typename List>
using tail = typename Tail<List>::type;
template<typename T>
class PopFront;
template<typename Head,typename ...Tail>
class PopFront<TypeList<Head,Tail...>>
{
public:
using type = TypeList<Tail...>;
};
template<typename List>
using pop_front = typename PopFront<List>::type;
template<typename T,typename NewType>
class PushFrontT;
template<typename ...Types,typename NewType>
class PushFrontT<TypeList<Types...>,NewType>
{
public:
using type = TypeList<NewType,Types...>;
};
template<typename List,typename NewType>
using push_front = typename PushFrontT<List,NewType>::type;
template<typename T,typename NewType>
class PushBack;
template<typename ...Types,typename NewType>
class PushBack<TypeList<Types...>,NewType>
{
public:
using type = TypeList<Types...,NewType>;
};
template<typename List,typename NewType>
using push_back = typename PushBack<List,NewType>::type;
template<typename List,std::size_t N>
class NthType : public NthType<pop_front<List>,N - 1>
{};
template<typename List>
class NthType<List,0> : public Front<List>
{};
template<typename List,std::size_t N>
using NType = typename NthType<List,N>::type;
template<typename ...Args>
std::tuple<Args...> Tuple(TypeList<Args...>)
{
return std::tuple<Args...>();
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wkhgit/generic.git
git@gitee.com:wkhgit/generic.git
wkhgit
generic
generic
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891