在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的更多相关文章

  1. IntelliJ IDEA 14.x 快捷键/个性化设置

    常用快捷键设置(设置成跟Eclipse差不多) 按照路径:File -> Settings -> Appearance & Behavior -> Keymap -> ...

  2. 17款code review工具

    本文是码农网原创翻译,转载请看清文末的转载要求,谢谢合作! 好的代码审查器可以大大地帮助程序员提高代码质量,减少错误几率. 虽然现在市场上有许多可用的代码审查工具,但如何挑选也是一个艰巨的任务.在咨询 ...

  3. CV code references

    转:http://www.sigvc.org/bbs/thread-72-1-1.html 一.特征提取Feature Extraction:   SIFT [1] [Demo program][SI ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 初次接触:DirectDraw

    第六章 初次接触:DirectDraw 本章,你将初次接触DirectX中最重要的组件:DirectDraw.DirectDraw可能是DirectX中最强大的技术,因为其贯穿着2D图形绘制同时其帧缓 ...

  9. 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 ...

随机推荐

  1. 《Diagnostic use of facial image analysis software in endocrine and genetic disorders: review, current results and future perspectives》学习笔记

    <使用面部图像分析软件诊断内分泌和遗传疾病:回顾,当前研究结果以及未来展望> Abstract 库欣综合征(CS)和肢端肥大症普遍是在发病后几年才能被诊断出的内分泌疾病.现在需要新的诊断方 ...

  2. Troubleshoot Refused VNC Connection in CentOS 7

    Troubleshoot Refused VNC Connection in CentOS 7 Posted on March 15, 2015 by Istvan Szarka — 2 Commen ...

  3. RaisingStudio.PackageManager 发布 1.0版

    从此免去命今行打包的痛苦,安装本Module后,可以在Dashbaord的Modules里看到一个Download页,进入可看到全部已安装模块列表(与Installed页内容一致),可搜索找到要打包的 ...

  4. 鸟瞰Nodejs

    一,基础. 1,Node的包管理器:npm; 安装node环境时会自动安装. 本地模式获取一个包:npm install [package_name] 此时包被安装到当前木的node_modules子 ...

  5. REST API 安全设计指南

    0x01 REST API 简介 REST的全称是REpresentational State Transfer,表示表述性无状态传输,无需session,所以每次请求都得带上身份认证信息.rest是 ...

  6. 基于OWIN WebAPI 使用OAuth授权服务【客户端验证授权(Resource Owner Password Credentials Grant)】

    适用范围 前面介绍了Client Credentials Grant ,只适合客户端的模式来使用,不涉及用户相关.而Resource Owner Password Credentials Grant模 ...

  7. node-webkit教程(16)调试typescript

    原文链接:node-webkit教程(16)调试typescript 本文所讲的内容同样适用于chrome浏览器. 在chrome的开发人员工具的配置项中,有一个sourcemap的选项,用来配置ja ...

  8. clean code meaningful names

    ---恢复内容开始--- Meaningful Names: use Intention-Revealing Names //nice,Everyone who reads your code (in ...

  9. Local Optimization Revisited

    十年前刚入行的时候,做为一名被agile刚洗脑的新兵,觉得自己仿佛掌握了什么神兵秘器.你看,你们这里那里都是在做local optimization,你看你不懂什么叫value driven吧,你做这 ...

  10. com组件远程桌面rdp模块的调用

    rdp(remote desktop protocol)是一个多通道的协议,包括客户端视音传输.文件传输和通讯端口转向等等功能,通过压缩处理的数据网络传输也是相当快.我们在windows操作系统下面, ...