Boost.Hana

Boost.Hana 是一个元编程的库。它为不同种类数据的集合以及类型的集合提供了容器和算法。

#include <boost/hana.hpp>
namespace hana = boost::hana; #include <cassert>
#include <iostream>
#include <string>
struct Fish { std::string name; };
struct Cat { std::string name; };
struct Dog { std::string name; }; auto animals = hana::make_tuple(Fish{"Nemo"}, Cat{"Garfield"}, Dog{"Snoopy"}); int main()
{
using namespace hana::literals;
// Access tuple elements with operator[] instead of std::get.
Cat garfield = animals[1_c];
// Perform high level algorithms on tuples (this is like std::transform)
auto names = hana::transform(animals, [](auto a) {
return a.name;
});
assert(hana::reverse(names) == hana::make_tuple("Snoopy", "Garfield", "Nemo")); auto animal_types = hana::make_tuple(hana::type_c<Fish*>, hana::type_c<Cat&>, hana::type_c<Dog>);
auto no_pointers = hana::remove_if(animal_types, [](auto a) {
return hana::traits::is_pointer(a);
});
static_assert(no_pointers == hana::make_tuple(hana::type_c<Cat&>, hana::type_c<Dog>), ""); auto has_name = hana::is_valid([](auto&& x) -> decltype((void)x.name) { });
static_assert(has_name(garfield), "");
static_assert(!has_name(1), "");
}

Boost.Hana的更多相关文章

  1. Boost.Hana在visual studio 2017 rc中的残缺使用

    最新的visual studio还不支持hana,不知道vs2017正式版本出后会不会支持.等不及了,先用rc版试试吧. 1.从https://github.com/boostorg/hana下载或拉 ...

  2. zz A list of open source C++ libraries

    A list of open source C++ libraries < cpp‎ | links http://en.cppreference.com/w/cpp/links/libs Th ...

  3. C++模板杂谈

    在模板编程中,有几个常用的技术:模板(偏)特化,特性萃取,标签分派,匹配失败不是错误.其中模板(偏)特化是基础,匹配失败不是错误(SFINAE)应用最为广泛. 现代C++对模板编程做了更多的加强,bo ...

  4. C++17尝鲜:variant

    variant variant 是 C++17 所提供的变体类型.variant<X, Y, Z> 是可存放 X, Y, Z 这三种类型数据的变体类型. 与C语言中传统的 union 类型 ...

  5. awesome-modern-cpp

    Awesome Modern C++ A collection of resources on modern C++. The goal is to collect a list of resouce ...

  6. An Introduction to Reflection in C++

    Apr 13, 2017 Stop me if you’ve heard this one before. You are working on a messaging middleware, a g ...

  7. C++17尝鲜

    https://cloud.tencent.com/developer/article/1351910 [译]C++17,optional, any, 和 variant 的更多细节 用户261520 ...

  8. Boost 1.61.0 Library Documentation

    http://www.boost.org/doc/libs/1_61_0/ Boost 1.61.0 Library Documentation Accumulators Framework for ...

  9. boost强分类器的实现

    boost.cpp文件下: bool CvCascadeBoost::train( const CvFeatureEvaluator* _featureEvaluator, int _numSampl ...

随机推荐

  1. java的关键字:static、final

    java的 static: 性质 静态对象 非静态对象 拥有属性: 是类共同拥有的 是类各对象独立拥有的 内存分配: 内存空间上是固定的 空间在各个附属类里面分配 分配顺序: 先分配静态对象的空间 继 ...

  2. yii2 笔记(1)

    1.js文件加载顺序问题 在视图中引用js文件的时候,使用到jquery会报错,因为自定义的js文件在jquery之前被引入了. 由于jquery,bootstrap是在AppAsset中全局引入的, ...

  3. JZ2440 裸机驱动 第12章 I2C接口

    本章目标: 了解I2C总线协议: 掌握S3C2410/S3C2440中I2C接口的使用方法: 12.1 I2C总线协议及硬件介绍 12.1.1 I2C总线协议 1 I2C总线的概念 2 I2C总线的信 ...

  4. 【python】实例-创建文件并通过键盘输入字符

    import os lnend=os.linesep ##windows行结束符号是“\r\n” FileName=raw_input("please input filename:&quo ...

  5. 【shell】grep命令

    1.作用Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来.grep全称是Global Regular Expression Print,表示全局 ...

  6. 带你走进Linux(Ubuntu)

    类Unix系统目录结构 ubuntu没有盘符这个概念,只有一个根目录/,所有文件都在它下面 /:根目录,一般根目录下只存放目录,在Linux下有且只有一个根目录.所有的东西都是从这里开始.当你在终端里 ...

  7. json_encode 中文 null

    今天使用json_encode 结果中文变成了null 原来是编码的问题. 将编码由 GBK 转成utf-8的就可以了 iconv('gb2312','utf-8', '中文');

  8. ghost系统下,C#获取时间带星期几的解决办法

    cmd   regedit打开注册表,进入到[HKEY_USERS\.DEFAULT\Control Panel\International]  ,然后1.将键 sDate 的值由 / 改为 - 2. ...

  9. jquery.cookie.js $.cookie()是怎么使用

    jquery.cookie() 方法的使用(读取.写入.删除) <script type="text/javascript" src="js/jquery.cook ...

  10. shell 2变量

    shell变量 定义变量 变量名命名规则: 1.命名只能使用英文字母.数字和下划线,首个字符不能以数字开头 2.中间不能有空格,可以使用下划线 3.不能使用标点符号 4.不能使用sh中的关键字,可用h ...