当前位置: 首页 > news >正文

做网站必须购买空间吗?站长工具无忧

做网站必须购买空间吗?,站长工具无忧,在线网站建设,建站前期准备C 实现一个type list 模板,在编译期计算。这个type list主要有构造,列表头类型,列表尾类型,concat操作,去除列表元素重复,获取指定元素,删除指定元素的操作。实现代码贴在下面: #pr…

C++ 实现一个type list 模板,在编译期计算。这个type list主要有构造,列表头类型,列表尾类型,concat操作,去除列表元素重复,获取指定元素,删除指定元素的操作。实现代码贴在下面:

#pragma once
#include <iostream>
#include <typeinfo>namespace type_list {// Step 1: 基础类型列表定义// 定义空列表template <typename ...Types>struct list {};// 非空列表的递归定义template <typename Type, typename ...Types>struct list<Type, Types...> {using head = Type;using tail = list<Types...>;};// 定义空列表类型using empty_list = list<>;// Step 2: 获取列表头部类型template <typename TypeList>using head_t = typename TypeList::head;// 获取列表尾部类型template <typename TypeList>using tail_t = typename TypeList::tail;// 构造新列表template <typename Head, typename Tail>struct construct;template <typename Head, typename Tail>using construct_t = typename construct<Head, Tail>::type;template <typename Head, typename ...Types>struct construct<Head, list<Types...>> {using type = list<Head, Types...>;};///template<typename TypeList>struct size;// 模板辅助类template<typename TypeList>constexpr size_t size_v = size<TypeList>::value;//size的模板特化,继承了std::integral_constanttemplate<typename...Types>struct size<list<Types...>> : std::integral_constant<std::size_t, sizeof...(Types)> {};template<class TypeList>constexpr bool empty_v = (size_v<TypeList> == 0);template<class TypeList>struct empty : std::bool_constant<empty_v<TypeList>> {};template<class TypeList>constexpr bool empty_s = empty<TypeList>::value;/// 查找模板的制定索引的value//声明一个模板;template<std::size_t Index, class TypeList>struct get;template<std::size_t Index, class TypeList>using get_t = typename get<Index, TypeList>::type;template<std::size_t Index, class TypeList>struct get {using type = get_t<Index - 1, tail_t<TypeList>>;};template<class TypeList>struct get<0, TypeList> {using type = head_t<TypeList>;};/// concattemplate<typename TypeList1, typename TypeList2>class concat;template<typename T, typename U>using concat_t = typename concat<T, U>::type;template<typename ...T, typename ...U>class concat<list<T...>, list<U...>> {public:using type = list<T..., U...>;};// delete specific typetemplate<typename TypeList, typename Type>class remove_all;template<typename TypeList, typename Type>using remove_all_t = typename remove_all<TypeList, Type>::type;template<typename TypeList, typename Type>class remove_all {public:using head = head_t<TypeList>;using tail = tail_t<TypeList>;using clean_tail = remove_all_t<tail, Type>;using type = std::conditional_t<std::is_same_v<head, Type>, clean_tail, construct_t<head, clean_tail>>;};template<typename Type>class remove_all<empty_list, Type> {public:using type = empty_list;};// get the last typetemplate<typename TypeList>class last;template<typename TypeList>using last_t = typename last<TypeList>::type;template<typename TypeList>class last {public:using type = last_t<tail_t<TypeList>>;};// 递归终止template<typename Type>class last<list<Type>> {public:using type = Type;};// distinct list typetemplate<typename TypeList>class distinct;template<typename TypeList>using distinct_t = typename distinct<TypeList>::type;template <typename TypeList>class distinct{public:using type = construct_t<head_t<TypeList>,distinct_t<remove_all_t<tail_t<TypeList>, head_t<TypeList>>>>;};// 递归终止template <>struct distinct<empty_list> {using type = empty_list;};// print listtemplate<typename T>void print_type() {int status;std::cout << typeid(T).name() << std::endl;}// 打印类型列表template <typename TypeList>struct print_list;template <typename TypeList>void print_list_func() {print_list<TypeList>::print();}// 主模板,递归地打印类型列表template <typename TypeList>struct print_list {static void print() {print_type<head_t<TypeList>>();print_list_func<tail_t<TypeList>>();}};// 终止递归的特化版本template <>struct print_list<empty_list> {static void print() {// 空列表,不打印任何内容}};} // namespace type_list

测试代码

#pragma once#include "type_list.h"
#include <iostream>using namespace std;void test_type_list() {//1.define listusing MyList = type_list::list<int, double, char>;using AnotherList = type_list::list<float, int>;using EmptyList = type_list::list<>;//2. get the head and tail type of listusing MyListHead = type_list::head_t<MyList>;using MyListTail = type_list::tail_t<MyList>;static_assert(std::is_same_v<MyList::tail, type_list::list<double,char>>, "MyList head shoud be int");static_assert(std::is_same_v<MyListTail, type_list::list<double, char>>, "MyList head shoud be int");static_assert(std::is_same_v<MyListHead, int>, "MyList head shoud be int");static_assert(std::is_same_v<MyList::head, int>, "MyList head shoud be int");//3. get list sizeconstexpr std::size_t listSize = type_list::size_v<MyList>;std::cout << listSize << std::endl;// 4. emptystatic_assert(type_list::empty_s<EmptyList>, "is empty");static_assert(type_list::empty_v<EmptyList>, "is empty");// 5. get index posusing FirstType = type_list::get_t<1, MyList>;static_assert(std::is_same_v<FirstType, double>, "not equal");// 6.concat listusing ConcatList = type_list::concat_t<MyList, AnotherList>;using ConcatListHead = type_list::head_t<ConcatList>;static_assert(std::is_same_v<ConcatListHead, int>, "head should be int");static_assert(std::is_same_v<ConcatList::head, int>, "head should be int");constexpr std::size_t concat_list_size = type_list::size_v<ConcatList>;cout << "concat_list_size : " << concat_list_size << endl;// 6.delete list typeusing RemoveIntList = type_list::remove_all<MyList, int>;static_assert(std::is_same_v<type_list::head_t<RemoveIntList>, int>, "the list head shoud not be int");// 6.delete list typeusing LastType = type_list::last_t<MyList>;static_assert(std::is_same_v<LastType, char>, "the last type should be char");// distinct list typeusing RepeatList = type_list::list<int, double, char, int, double, char, int,int,int>;using DistType = type_list::distinct_t<RepeatList>;std::cout << "--------------------------" << endl;type_list::print_list_func<RepeatList>();std::cout << "--------------------------" << endl;type_list::print_list_func<DistType>();std::cout << "--------------------------" << endl;}
http://www.hengruixuexiao.com/news/47108.html

相关文章:

  • wordpress 分类目录 首页windows优化大师手机版
  • 宣城高端网站建设外贸网站平台有哪些
  • 青海最好的网站建设公司新闻最近的新闻
  • 深圳外贸集团湖南正规关键词优化首选
  • 商城网站建设目的百度一下首页百度一下
  • 做微商哪个网站有客源个人网页怎么做
  • 网站建设客服回访话术大全深圳推广公司
  • 衡水做网站服务商百度自动搜索关键词软件
  • 网站建设学什么语言个人如何优化网站有哪些方法
  • 昆山网站建设ikelv小程序开发软件
  • 网站开发案例pdf石家庄关键词快速排名
  • 男女做那个能看的视频网站搜索引擎营销seo
  • 宿迁公司做网站百度ocpc如何优化
  • 深圳网站建设公司专业百度开户推广多少钱
  • 网站建设的原则百度在线扫题入口
  • 本地郑州网站建设长春头条新闻今天
  • 什么网站做外贸好宁波seo网络推广软件系统
  • 宁波网站建设佳选蓉胜网络好网络营销的理解
  • 政务微网站建设方案二维码推广赚佣金平台
  • 做加工都在哪个网站推广31省市新增疫情最新消息
  • 南山做网站公司有哪些线上推广的方式
  • 网站平台建设方案策划书企业整站优化
  • 佛山医疗网站建设短视频推广公司
  • 易语言网站怎么做灰色关键词排名
  • 政府网站建设分析优秀营销软文范例300字
  • 做企业网站的缺点东莞网络推广培训
  • 福州seo建站推广小程序
  • 广告联盟没有网站怎么做厦门seo报价
  • 有口碑的坪山网站建设seo专员是做什么的
  • 人社部能力建设中心网站seo网页优化公司