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

More C++ Idioms/Metafunction

Metafunction的更多相关文章

  1. Python2.6-原理之类和oop(下)

    来自<python学习手册第四版>第六部分 五.运算符重载(29章) 这部分深入介绍更多的细节并看一些常用的重载方法,虽然不会展示每种可用的运算符重载方法,但是这里给出的代码也足够覆盖py ...

  2. 一道模板元编程题源码解答(replace_type)

    今天有一同学在群上聊到一个比较好玩的题目(本人看书不多,后面才知是<C++模板元编程>第二章里面的一道习题), 我也抱着试一试的态度去完成它, 这道题也体现了c++模板元编程的基础和精髓: ...

  3. C# Windows Service服务的创建和调试

    前言 关于Windows服务创建和调试的文章在网络上的很多文章里面都有,直接拿过来贴在这里也不过仅仅是个记录,不会让人加深印象.所以本着能够更深刻了解服务项目的创建和调试过程及方法的目的,有了这篇记录 ...

  4. 可爱的 Python : Python中函数式编程,第二部分

    英文原文:Charming Python: Functional programming in Python, Part 2,翻译:开源中国 摘要:  本专栏继续让David对Python中的函数式编 ...

  5. 千行代码入门Python

    这个是从网上找到的一份快速入门python的极简教程,大概一千行左右,个人觉得不错,特此收藏以备后用. # _*_ coding: utf-8 _*_ """类型和运算- ...

  6. More C++ Idioms

    Table of Contents Note: synonyms for each idiom are listed in parentheses. Adapter Template TODO Add ...

  7. 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 ...

  8. Lua只读表

    利用Lua的元表(metatable)和元函数(metafunction)可以很简单的实现此功能. 其实现大致分为三个部分 1.禁止在表中创建新值 2.禁止改变已有的值 3.将子表也变为只读 1.禁止 ...

  9. Python Syntax Summary

    # _*_ coding: utf-8 _*_ """########################################################## ...

随机推荐

  1. Spring 注入数据源

    一.在项目中添加dataSource所用到的包 dbcp数据源所需包:     commons-dbcp.jar     commons-pool.jar C3P0数据源所需包:     c3p0-0 ...

  2. 原生的UITableViewCell高度自适应,textLabel自动换行显示

    /* * 设置子项cell **/ - (UITableViewCell *)getChildCell:(UITableView *)tableView and:(NSIndexPath *)inde ...

  3. 如何使用NODEJS+REDIS开发一个消息队列

    作者: RobanLee 原创文章,转载请注明: 萝卜李 http://www.robanlee.com MQ全称为Message Queue, 消息队列(MQ)是一种应用程序对应用程序的通信方法.应 ...

  4. jquery 项目所用

    <script> $(document).ready(function(){ $.ajax({ type:'post', url :'interface.ajax.php', data:{ ...

  5. 自己写的轻量级PHP框架trig与laravel5.1,yii2性能对比

    看了下当前最热门的php开发框架,想对比一下自己写的框架与这些框架的性能对比.先看下当前流行框架的投票情况. 看结果对比,每个测试脚本做了一个数据库的联表查询并进行print_r输出,查询的sql语句 ...

  6. Object转换为JSON格式字符串

    简介: 把JS的Object转换为Json字符串. 代码: function ObjectToJson(object) { // Object转换为josn var json = "&quo ...

  7. ORA-01653:表无法通过64(在表空间USERS中)扩展

    问题描述:oracle插入数据时显示ORA-01653 表无法通过64(在表空间USERS中)扩展 原因:  oracle  表空间满了,需要扩展 截图: 解决方法: 1.首先查下表空间 select ...

  8. MYSQL 时间计算的 3 种函数

    方法 1. 加法 adddate('date_expression',interval value type); 'date_expression' + interval value type; -- ...

  9. Z-Stack协议中几个重要概念的理解

    1. 原语     ZigBee设备在工作时,各种不同的任务在不同的层次上执行,通过层的服务,完成所要执行的任务.每一层的服务主要完成两种功能:根据它的下层服务要求,为上层提供相应的服务:另一咱是根据 ...

  10. delphi代码实现创建dump文件

    I used a "watchdog" thread for this, which checks if the mainform is responding, and make ...