首页 > 其他分享 >Template Metaprogramming

Template Metaprogramming

时间:2023-07-15 19:47:43浏览次数:33  
标签:Metaprogramming TypeList result template using Template type struct

#include<bits/stdc++.h>
using namespace std;
template<typename...>struct TypeList;
template<typename Head,typename...Tails>
struct TypeList<Head,Tails...>{
    using head=Head;
    using tails=TypeList<Tails...>;
};
template<>struct TypeList<>{};
template<typename TList,unsigned int index>struct TypeAt;
template<typename Head,typename...Args>
struct TypeAt<TypeList<Head,Args...>,0>{
    using type=Head;
};
template<typename Head,typename...Args,unsigned int i>
struct TypeAt<TypeList<Head,Args...>,i>{
    static_assert(i<sizeof...(Args)+1,"i out of range");
    using type=typename TypeAt<TypeList<Args...>,i-1>::type;
};
template<typename TList,typename T>struct IndexOf;
template<typename Head,typename...Tails,typename T>
struct IndexOf<TypeList<Head,Tails...>,T>{
	private:
	    using Result=IndexOf<TypeList<Tails...>,T>;
	public:
	    static constexpr int value=is_same<Head,T>::value?0:
	    	(Result::value==-1?-1:Result::value+1);
};
template<typename T>
struct IndexOf<TypeList<>,T>{
    static constexpr int value=-1;
};
template<typename,typename>struct Append;
template<typename...TList,typename T>
struct Append<TypeList<TList...>,T>{
    using result_type=TypeList<TList...,T>;
};
template<typename T,typename...TList>
struct Append<T,TypeList<TList...>>{
    using result_type=TypeList<T,TList...>;
};
template<typename...TListLeft,typename...TListRight>
struct Append<TypeList<TListLeft...>,TypeList<TListRight...>>{
    using result_type=TypeList<TListLeft...,TListRight...>;
};
template<typename TList,typename T>struct Erase;
template<typename Head,typename...Tails,typename T>
struct Erase<TypeList<Head,Tails...>,T>{
    using result_type=typename Append<Head,typename Erase<TypeList<Tails...>,T>::result_type>::result_type;
};
template<typename...Tails,typename T>
struct Erase<TypeList<T,Tails...>,T>{
    using result_type=TypeList<Tails...>;
};
template<typename T>
struct Erase<TypeList<>,T>{
    using result_type=TypeList<>;
};
int main(){
	
	return 0;
}

标签:Metaprogramming,TypeList,result,template,using,Template,type,struct
From: https://www.cnblogs.com/2021changqing52/p/17556736.html

相关文章

  • springboot redis工具类之StringRedisTemplate 使用
    1、StringRedisTemplate是什么?StringRedisTemplate继承自RedisTemplate类,实现了BeanClassLoaderAware,Aware,InitializingBean,RedisOperations<K,V>接口。StringRedisTemplate是RedisTemplate以字符串为中心的扩展,由于针对Redis的大多数操作都是基于字符串的,因此此类提供了一个......
  • JdbcTemplate(操作数据库-查询返回对象、查询返回集合)
    实现类:packageorg.example.spring.dao;importorg.example.spring.entity.Book;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.jdbc.core.BeanPropertyRowMapper;importorg.springframework.jdbc.core.JdbcTemplate;im......
  • RedisTemplate 的简单使用
    redisTemplate.opsForValue() 方法可以获得一个RedisString的操作类,通过该类可以执行一系列字符串类型数据的操作,例如获取、设置、删除数据等。//示例1:设置字符串类型的数据redisTemplate.opsForValue().set("key","value");//示例2:获取字符串类型的数据String......
  • template snippet
     {%forreviewinreviews%}{%ifforloop.first%}<p>{{review.review}}</p>{%endif%}{%endfor%} {%forvalueinvalues%}<p>count:{{forloop.counter}}</p><p>value:{{value}}</p>{......
  • linux shell template
    Replaceenvironmentvariablesinafilewiththeiractualvalues?#config.xml<property><name>instanceId</name><value>$INSTANCE_ID</value></property><property><name>rootPath</name>......
  • WordPress主题,当前页面使用了哪个template模板文件?
    对于页面与模板的对应情况一般都是能确定的,不过新朋友一时不熟悉可能还是需要花一点时间。其实,可以有一个小技巧,可以快速确定当前页面对应的模板文件。想要实现上面的效果,只需将下面代码加入主题的 functions.php 文件。functionzhuige_admin_bar_init(){//Ifnota......
  • 2023-01-26-Poly Template
    尝试强行记忆,尝试失败。。。把最终所有的式子写一遍。约定\(F^{*}(x)\)表示\(\pmod{x^{n/2}}\)意义下的结果,\(F^{R}(x)\)表示系数翻转。\(\mathtt{Summary}\)\(\mathtt{Poly\INV}\)\[G(0)=F(0)'\\G(x)=G^{*}(x)(2-F(x)G^{*}(x))\]\(\mathtt{Poly\Sqrt}\)\[......
  • IDEA: File and code Templates IntelliJ IDEA 2023.1
     https://www.jetbrains.com/help/idea/file-template-variables.html  /**encoding:utf-8*版权所有${YEAR}涂聚文有限公司*许可信息查看:*描述:#Author:geovindu,GeovinDu涂聚文.#IDE:IntelliJIDEA2023.1Java17#Datetime:${YEAR......
  • Property ‘sqlSessionFactory‘ or ‘sqlSessionTemplate‘ are required 问题解决
    以下是报错日志解决方案确认以下配置是否都存在:1、配置文件有写mybatis配置2、启动类里加上Mapper扫描的注解(指向自己mapper存放的位置)3、删除SpringBootApplication注解的exclude属性:@SpringBootApplication(exclude={DataSourceAutoConfiguration.class,DataSourc......
  • 在JAVA中使用mongoTemplate构造查询条件
    //创建条件对象Criteriacriteria=newCriteria();//3.单个条件查询多个字段(客户编号)if(StringUtils.isNotEmpty(bo.getAdmpId())){criteria.orOperator(Criteria.where("final_uid").is(bo.getAdmpId()),Criteria.where("customer_......