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. winform datagridview 不显示默认第一列 不显示未绑定列 数据源发生改变时自动更新 (转)

    不显示带星号的第一列: datagridview属性框中将 RowHeadersVisiber 设置为  false 不显示未绑定列: datagridview有一个属性是 AutoGenerateC ...

  2. golang defer的使用

    defer一般用于在函数结束时执行必要的处理工作.例如,关闭文件描述符,关闭网络连接等等. 函数中可以定义多个defer,执行的时候按照先进后出的顺序. defer定义的语句,即使遇到panic,也会 ...

  3. oracle 导入excel

    方法二.利用PLSQL Developer使用PLSQL Developer工具,这个可是大名鼎鼎的Oracle DBA最常使用的工具.在单个文件不大的情况下(少于100000行),并且目的表结构已经 ...

  4. thinkphp 3.2.3在nginx+php下的url重写配置经验

    环境:centos7.2+lnmp1.3(nginx+php7.0+mysql5.5) 进入服务器配置路径:cd /usr/local/nginx/conf/nginx.conf 修改nginx.co ...

  5. 复分析可视化方法:笔记:log(z)的可视化微分法

    当z转过θ时,我们来看看发生了什么: 左图中的空心箭头代表z的变化量,其长度为rδ,方向为pi/2+θ: 右图中的实心箭头代表log(z)的变化量,其长度为δ,方向为pi/2. 因此,从左图空心箭头到 ...

  6. 小峰servlet/jsp(5)jsp自定义标签

    一.自定义标签helloworld: 二.自定义有属性的标签: HelloWorldTag.java:继承TagSupport: package com.java1234.tag; import ja ...

  7. 【比特币】SPV是如何工作的

    SPV是如何工作的 SPV, Bloom 过滤器和检查点 这是一篇技术文章,获取比特币的工作知识. 一个完整的节点,比如比特币核心,知道以下几点: 每一个当前正在围绕网络广播事务处理 每一个曾经被送到 ...

  8. [UE4]安卓打包成一个apk

    勾上就可以了

  9. 深入理解HTTP协议之POST方法——ajax实例

    作者:吴俊杰 性别:男 邮箱:sshroot@126.com 文章类型:原创 博客:http://www.cnblogs.com/voiphudong/ 一.说明http协议其实是一个相对比较简单的应 ...

  10. 解决不能正常访问workerman的问题

    问题描述: 在阿里云ECS上部署了workerman的应用(ECS是专有网络),在ECS安全组里已经允许workerman需要的全部端口,但是外网一直不能正常打开(注,其他服务,比80端口外部是可以用 ...