Boost.Hana
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的更多相关文章
- Boost.Hana在visual studio 2017 rc中的残缺使用
最新的visual studio还不支持hana,不知道vs2017正式版本出后会不会支持.等不及了,先用rc版试试吧. 1.从https://github.com/boostorg/hana下载或拉 ...
- 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 ...
- C++模板杂谈
在模板编程中,有几个常用的技术:模板(偏)特化,特性萃取,标签分派,匹配失败不是错误.其中模板(偏)特化是基础,匹配失败不是错误(SFINAE)应用最为广泛. 现代C++对模板编程做了更多的加强,bo ...
- C++17尝鲜:variant
variant variant 是 C++17 所提供的变体类型.variant<X, Y, Z> 是可存放 X, Y, Z 这三种类型数据的变体类型. 与C语言中传统的 union 类型 ...
- awesome-modern-cpp
Awesome Modern C++ A collection of resources on modern C++. The goal is to collect a list of resouce ...
- 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 ...
- C++17尝鲜
https://cloud.tencent.com/developer/article/1351910 [译]C++17,optional, any, 和 variant 的更多细节 用户261520 ...
- Boost 1.61.0 Library Documentation
http://www.boost.org/doc/libs/1_61_0/ Boost 1.61.0 Library Documentation Accumulators Framework for ...
- boost强分类器的实现
boost.cpp文件下: bool CvCascadeBoost::train( const CvFeatureEvaluator* _featureEvaluator, int _numSampl ...
随机推荐
- JUC线程池之 Callable和Future
Callable 和 Future 简介 Callable 和 Future 是比较有趣的一对组合.当我们需要获取线程的执行结果时,就需要用到它们.Callable用于产生结果,Future用于获取结 ...
- WPF Demo7
没有Path/Source的数据绑定 本地local资源用法 namespace Demo9 { public class Student { private string name; public ...
- debian的pdf阅读器
www.foxitsoftware.cn下载deb包 或者 sudo apt-get install evince
- 2018-2019 20165226 网络对抗 Exp1 PC平台逆向破解
2018-2019 20165226 网络对抗 Exp1 PC平台逆向破解 目录 一.逆向及Bof基础实践说明 二.直接修改程序机器指令,改变程序执行流程 三.通过构造输入参数,造成BOF攻击,改变程 ...
- 学习笔记之IKM C++ 11
https://github.com/haotang923/interview/tree/master/IKM Q1. If most of the calls to function foo() b ...
- 学习笔记之C/C++指针使用常见的坑
https://mp.weixin.qq.com/s/kEHQjmhNtSmV3MgHzw6YeQ 避免内存泄露 不再用到的内存没有释放,就叫做内存泄露 在C/C++中,通过动态内存分配函数(如mal ...
- Opencv 入门学习之图片人脸识别
读入图片,算法检测,画出矩形框 import cv2 from PIL import Image,ImageDraw import os def detectFaces(image_name): im ...
- [UE4]换枪需要做的事,容器:数组、集合、Map
换枪: 1.需要同时保存多把枪 2.换下去的枪需要隐藏,而不是销毁 3.换枪应该有动作 4.不同的枪应该有不同的行为 蓝图中常见的容器 1.数组 特点: 1.元素连续存放 2.通过索引访问 3.索引从 ...
- [UE4]让AI跑起来
让AI由静止状态变成跑步状态,做法跟玩家角色走路一样. 一.创建1D混合动画 二.在AI角色关联的动画蓝图中使用第一步创建的混合动画
- 高通QMI协议
QMI(Qualcomm MSM Interface,官方名称应该是Qualcomm Message Interface)是高通用来替代OneRPC/DM的协议,用来与modem通信. QMI协议定义 ...