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 _*_ """########################################################## ...
随机推荐
- 转JS技巧
前端已经被玩儿坏了!像console.log()可以向控制台输出图片等炫酷的玩意已经不是什么新闻了,像用||操作符给变量赋默认值也是人尽皆知的旧闻了,今天看到Quora上一个帖子,瞬间又GET了好多前 ...
- RTUILabel+正则表达式
RTLabel和RegexKitLite都要导入第三方库 使用Regexkitlite库进行正则表达式的解析 1.库是使用MRR,如果在ARC工程里面使用这个类,必须在project->buil ...
- HDU 5793 - A Boring Question
HDU 5793 - A Boring Question题意: 计算 ( ∑(0≤K1,K2...Km≤n )∏(1≤j<m) C[Kj, Kj+1] ) % 1000000007=? (C[ ...
- C - The Hardest Problem Ever
Description Julius Caesar lived in a time of danger and intrigue. The hardest situation Caesar ever ...
- JAVA异常使用_每个人都曾用过、但未必都用得好
一.抛出异常 vs. 返回错误代码 有人说“Well, an exception is a goto.”,但也有人言“makes the code simpler by visibly separat ...
- 手机触摸屏的JS事件
处理Touch事件能让你跟踪用户的每一根手指的位置.你可以绑定以下四种Touch事件: touchstart: // 手指放到屏幕上的时候触发 touchmove: // 手指在屏幕上移动的时候触发 ...
- PHP学习笔记,自己动手写个MVC的框架 -- base所有代码
<?php /** 名称:基础类 作用:引用参数处理类,加载基础配置, 作者:swordphp@126.com 创建日期:2013-07-31 **/ require_once(ROOT_PAT ...
- CodeForces 187A Permutations
反向思维,先求数组中不用处理的元素个数,再用n减去这个数,得到结果. #include <iostream> #include <cstring> #define maxn 2 ...
- python 解释器内建函数001
python解释器内建函数列表如下: 001.abs() 求绝对值 #!/usr/bin/python if __name__=="__main__": print(abs(-10 ...
- js中一些常用的基本函数
如何使用jquery刷新当前页面下面介绍全页面刷新方法:有时候可能会用到window.location.reload()刷新当前页面.parent.location.reload()刷新父亲对象(用于 ...