Metafunction
Metafunction is a more general idiom than type generator. Metafunctions that produce type(s) as a result is used as type generators.
Appearance:
- a class template in which all the parameters are types
- a class with publicly accessible type
type
Intent
- To encapsulate a complex type computation algorithm
- To generate a type using compile-time type selection tech
Metafunction idiom is the principal way of writing compile-time algorithms in C++.
Implementation of metafunctions is often based on template specializations.
Example
template<bool, class L, class R>
struct IF{
typedef R type;
};
template<class L, class R>
struct IF<true, L, R>{
typedef L type;
};
IF<false, int, long>::type i; // long i
IF<true, int, long>::type i; // int i
Reference
Metafunction的更多相关文章
- Python2.6-原理之类和oop(下)
来自<python学习手册第四版>第六部分 五.运算符重载(29章) 这部分深入介绍更多的细节并看一些常用的重载方法,虽然不会展示每种可用的运算符重载方法,但是这里给出的代码也足够覆盖py ...
- 一道模板元编程题源码解答(replace_type)
今天有一同学在群上聊到一个比较好玩的题目(本人看书不多,后面才知是<C++模板元编程>第二章里面的一道习题), 我也抱着试一试的态度去完成它, 这道题也体现了c++模板元编程的基础和精髓: ...
- C# Windows Service服务的创建和调试
前言 关于Windows服务创建和调试的文章在网络上的很多文章里面都有,直接拿过来贴在这里也不过仅仅是个记录,不会让人加深印象.所以本着能够更深刻了解服务项目的创建和调试过程及方法的目的,有了这篇记录 ...
- 可爱的 Python : Python中函数式编程,第二部分
英文原文:Charming Python: Functional programming in Python, Part 2,翻译:开源中国 摘要: 本专栏继续让David对Python中的函数式编 ...
- 千行代码入门Python
这个是从网上找到的一份快速入门python的极简教程,大概一千行左右,个人觉得不错,特此收藏以备后用. # _*_ coding: utf-8 _*_ """类型和运算- ...
- More C++ Idioms
Table of Contents Note: synonyms for each idiom are listed in parentheses. Adapter Template TODO Add ...
- 2D and 3D Linear Geometry Kernel ( Geometry Kernels) CGAL 4.13 -User Manual
1 Introduction CGAL, the Computational Geometry Algorithms Library, is written in C++ and consists o ...
- Lua只读表
利用Lua的元表(metatable)和元函数(metafunction)可以很简单的实现此功能. 其实现大致分为三个部分 1.禁止在表中创建新值 2.禁止改变已有的值 3.将子表也变为只读 1.禁止 ...
- Python Syntax Summary
# _*_ coding: utf-8 _*_ """########################################################## ...
随机推荐
- drupal 7.23 上传中文命名文件bug
$file->filename = trim(drupal_basename($_FILES['files']['name'][$source]), '.'); //在此行下 添加以下代码即可( ...
- HDU 5787 K-wolf Number
题意:l-r之间有多少个数,其连续k位不存在相同的数字 分析:数位dp,从高位开始向低位进行枚举.因为连续k个数字不相同,在枚举一个数字的时候, 要知道前k-1位的内容,这可以用一个4维的数组表示,再 ...
- BeeswaxException 以及其他问题
Could not read table BeeswaxException(handle=QueryHandle(log_context='ae18ae74-518f-400b-b4b0-d399ed ...
- ORACLE 绑定变量用法总结 .
之前对ORACLE中的变量一直没个太清楚的认识,比如说使用:.&.&&.DEIFINE.VARIABLE……等等.今天正好闲下来,上网搜了搜相关的文章,汇总了一下,贴在这里,方 ...
- Thinkphp excel导入导出
挺有用处的存一下 1.去PHPexcel 官网下载最新的程序下来 ☞ 飞机在这里 我用的是1.78 放在vender 里面 在 function.php 写两个方法 路径当然是这个 ☞Commo ...
- Print! Print! Print!
print语句可以实现打印--只是对程序员友好的标准输出流的接口而已. 从技术角度来讲,这是把一个或多个对象转换为其文本表达形式,然后发送给标准输出或另一个类似文件的流. 更详细地说,在Python中 ...
- QNDTU外壳及开发板
昨天从淘宝上淘来了个DTU外壳,翻出来之前的STM32开发板和GPRS模块开发板,今天准备复习一下开发板,把裸板跑起来. 晒一下装备: 两块开发板: 51n ...
- LoggingApplicationListener
org.springframework.boot:spring-boot:1.3.0.M1 spring-boot-1.3.0.M1.jar package org.springframework.b ...
- linux之grep实例讲解
文件testgrep内容: 1.显示所有包含San的行 2.显示所有以J开始的人名所在的行 3.显示所有以700结尾的行 4.显示所有不包括834的行 5.显示所有生日在December的行 ...
- 【UVA 10307 Killing Aliens in Borg Maze】最小生成树, kruscal, bfs
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=20846 POJ 3026是同样的题,但是内存要求比较严格,并是没有 ...