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 中的 hashcode

    在Java的Object类中有一个方法: public native int hashCode(); 根据这个方法的声明可知,该方法返回一个int类型的数值,并且是本地方法,因此在Object类中并没 ...

  2. win10激活命令

    以管理员方式打开命令提示符输入以下3条命令slmgr /ipk W269N-WFGWX-YVC9B-4J6C9-T83GX 按回车slmgr /skms 54.223.212.31 按回车slmgr ...

  3. Angular 4 路由介绍

    Angular 4 路由 1. 创建工程 ng new router --routing 2. 创建home和product组件 ng g component home ng g component ...

  4. oracle 恢复备份

    select * from dbconninfo update dbconninfo set url = 'jdbc:oracle:thin:@(description=(address_list=( ...

  5. 基于Hadoop开发网络云盘系统架构设计方案第一稿

    引言 云计算技术的发展,各种网络云盘技术如雨后春笋,层出不穷,百度.新浪.网易都推出了自己的云盘系统,本文基于开源框架Hadoop设计实现了一套自己的网络云盘系统,方案为初步设计方案,不断完善中. 一 ...

  6. windows下使用RedisCluster集群简单实例

    一.开发环境 ruby环境准备 下载 64位的 RubyInstaller并安装 地址http://rubyinstaller.org/downloads/勾选下面三个不用配置环境变量 Image.p ...

  7. shell 3数组

    shell数组 shell支持一维数组(不支持多维数组),并且没有限定数组的大小. 定义数组 shell中,用括号来表示数组,数组元素用空格分隔,下标从0开始,元素的类型 方式1 数组名=(值1 值2 ...

  8. Missing Number @leetcode

    Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...

  9. [UE4]计算2点坐标附近的坐标:线性插值法

    float distance = FVector::Distance(SelfLocation, TargetLocation); .f / distance; DrawDebugPoint(GetW ...

  10. HTC Vive前置摄像头API(未测试)

    /*WebCamTexture:网络摄像头材质 WebCamTexture.Play() 播放: WebCamTexture.Pause() 暂停: WebCamTexture.Stop() 停止:* ...