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. QJson 的使用

    下载 源码解压 https://github.com/flavio/qjson 复制 src 目录下所有 .h .cpp .hh 文件到项目目录 qjson,pro 文件添加 INCLUDEPATH ...

  2. [转载]提升进程权限-OpenProcessToken等函数的用法

    GetCurrentProcessID 得到当前进程的ID OpenProcessToken 得到进程的令牌句柄LookupPrivilegeValue 查询进程的权限 AdjustTokenPriv ...

  3. SharedPreferences基础

    见归档项目:SharedPreferencesDemo.zip 1.对于数据量较小,且有明显的K-V形式的数据而言,适合用SharedPreferences保存.SharedPreferences的数 ...

  4. 切记ajax中要带上AntiForgeryToken防止CSRF攻击

    在程序项目中经常看到ajax post数据到服务器没有加上防伪标记,导致CSRF被攻击,下面小编通过本篇文章给大家介绍ajax中要带上AntiForgeryToken防止CSRF攻击,感兴趣的朋友一起 ...

  5. python-整理--使用IDE

    如何使用python的IDE 安装好python3.4之后,默认有一个叫IDLE,就是目录lib/idlelib之下,是一个简单实用的工具. 在VS2013上安装一个插件就可以使用VS当IDE了.插件 ...

  6. Android的线程和线程池

    ---恢复内容开始--- 一.Android线程的形态 (一)AsyncTask解析 AysncTask简介:①.实现上封装了Thread和Handler   ②.不适合进行特别耗时的后台任务 Ays ...

  7. PHP学习笔记,自己动手写个MVC的框架

    最新在大家自己的博客的过程中,发现各种开源的博客系统都或多或少的用起来别扭.于是想动手自己写个博客系统.既然写,就想好好写.那就先写个MVC框架.一点一点来.写的过程中有很多想法.还希望大家能够多多指 ...

  8. Python即时网络爬虫:API说明

    API说明——下载gsExtractor内容提取器 1,接口名称 下载内容提取器 2,接口说明 如果您想编写一个网络爬虫程序,您会发现大部分时间耗费在调测网页内容提取规则上,不讲正则表达式的语法如何怪 ...

  9. 记glide框架使用中所遇到的问题

    最近实在是太忙,每有时间写博客.记得之前写过一篇关于glide加载图片不显示的博客,但是给出最终的解决方法.这次我将把在项目中使用glide所遇到的问题总结一下. 1.使用glide最好对glide进 ...

  10. html5 新增语义标签

    一份模板: <body> <header> <hgroup> <h1>Page title</h1> <h2>Page subt ...