C++14 make code cleaner
在C++11中我们如果要写一个通过tuple实现函数调用的函数要这样写:
template<int...>
struct IndexTuple{}; template<int N, int... Indexes>
struct MakeIndexes : MakeIndexes<N - , N - , Indexes...> {}; template<int... indexes>
struct MakeIndexes<, indexes...>
{
typedef IndexTuple<indexes...> type;
}; template<typename F, int ... Indexes, typename ... Args>
static void call_helper(F f, IndexTuple<Indexes...>, const std::tuple<Args...>& tup)
{
f(std::get<Indexes>(tup)...);
} template<typename F, typename ... Args>
static void call(F f, const std::tuple<Args...>& tp)
{
call_helper(f, typename MakeIndexes<sizeof... (Args)>::type(), tp);
}
在C++14中MakeIndexes和IndexTuple已经由utility库提供了,我们可以写得更简洁了,两个函数就可以了。
template<typename F, size_t... I, typename ... Args>
static void call_helper(F f, std::index_sequence<I...>, const std::tuple<Args...>& tup)
{
f(std::get<I>(tup)...);
} template<typename F, typename ... Args>
static void call(F f, const std::tuple<Args...>& tp)
{
call_helper(f, std::make_index_sequence<sizeof... (Args)>(), tp);
}
这样写更省心啦o(∩_∩)o 。
C++14 make code cleaner的更多相关文章
- IntelliJ IDEA 14.x 快捷键/个性化设置
常用快捷键设置(设置成跟Eclipse差不多) 按照路径:File -> Settings -> Appearance & Behavior -> Keymap -> ...
- 17款code review工具
本文是码农网原创翻译,转载请看清文末的转载要求,谢谢合作! 好的代码审查器可以大大地帮助程序员提高代码质量,减少错误几率. 虽然现在市场上有许多可用的代码审查工具,但如何挑选也是一个艰巨的任务.在咨询 ...
- CV code references
转:http://www.sigvc.org/bbs/thread-72-1-1.html 一.特征提取Feature Extraction: SIFT [1] [Demo program][SI ...
- Code Review Checklist and Guidelines for C# Developers
Checklist1. Make sure that there shouldn't be any project warnings.2. It will be much better if Code ...
- C# Development 13 Things Every C# Developer Should Know
https://dzone.com/refcardz/csharp C#Development 13 Things Every C# Developer Should Know Written by ...
- Java 8 Features – The ULTIMATE Guide--reference
Now, it is time to gather all the major Java 8 features under one reference post for your reading pl ...
- Back to Basics: Using KVO
One of the things I like most about Apple’s iOS SDK is the consistent and easy-to-use API they provi ...
- 初次接触:DirectDraw
第六章 初次接触:DirectDraw 本章,你将初次接触DirectX中最重要的组件:DirectDraw.DirectDraw可能是DirectX中最强大的技术,因为其贯穿着2D图形绘制同时其帧缓 ...
- A great tutorial with Jupyter notebook for ML beginners
An end to end implementation of a Machine Learning pipeline SPANDAN MADAN Visual Computing Group, Ha ...
随机推荐
- 如何处理webView跳转
- (void)webView:(UIWebView *)wv didFailLoadWithError:(NSError *)error { // Give iOS a chance to o ...
- [ASE][Daily Scrum]11.13
今天的计划如下: View Shilin Liu 修复残缺地图下的行进问题 Client Jiafan Zhu(回学校了) 和服务器端对接测试 Yiming Liao ...
- Hadoop-1.2.1 安装步骤小结(ubuntu)
1.安装ubuntu系统 如果不使用云服务器,可以使用虚拟机WmWare安装,具体安装步骤这里就不讲了,ubuntu系统下载地址:http://www.ubuntu.com/download/desk ...
- libqrencode 3.4.3 发布,二维码的C解析库
libqrencode 3.4.3 的命令行增加了 --rle 参数,修复了开发库和命令行工具的一些小 bug. libqrencode (QRencode) 是一个用C语言编写的用来解析二维条形码( ...
- elixir 高可用系列(三) GenEvent
概述 GenEvent 是事件处理的通用部分的抽象. 通过 GenEvent ,我们给已有的服务 动态 的添加 事件处理. GenEevent 和 GenServer 的区别 之前已经介绍了 GenS ...
- Orleans中的Timer和Reminder
Timers and Reminder 定时器和提醒器 Orleans runtime 允许开发人员通过一种叫做timer和另一种叫做reminder的机制为grain添加周期性行为.接下来我分别为大 ...
- C#设计模式(6)——原型模式(Prototype Pattern)
一.引言 在软件系统中,当创建一个类的实例的过程很昂贵或很复杂,并且我们需要创建多个这样类的实例时,如果我们用new操作符去创建这样的类实例,这未免会增加创建类的复杂度和耗费更多的内存空间,因为这样在 ...
- Window程序的安装与部署
步骤: 1.新建项目—选择安装与部署—安装项目或使用安装向导,再这里我用的是安装向导 2.点击确定—下一步 3.点击下一步,选择主输出 4.点击下一步,添加文件 5.点击完成 设置: 右击安装项目 出 ...
- Local Optimization Revisited
十年前刚入行的时候,做为一名被agile刚洗脑的新兵,觉得自己仿佛掌握了什么神兵秘器.你看,你们这里那里都是在做local optimization,你看你不懂什么叫value driven吧,你做这 ...
- paip. 内存占用少的php ide选择评测总结
paip. 内存占用少的php ide选择评测总结 php ide主要以内存占用为标准进行评测.. 其次以软件体积为标准.. 作者Attilax 艾龙, EMAIL:1466519819@qq.c ...