在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. 黑马程序员——for循环的使用与理解

    Console.WriteLine("请输入要打印菱形的行数(不能是偶数)");---------------------- <a href="http://edu ...

  2. [Hyper-V]使用操作系统模板创建新的虚拟机

    描述: 为了节省空间和时间的目的,先在Hyper-V里创建一个干净的操作系统,以后再创建虚拟机时都基于此操作系统,节省了安装Windows的时间 另外创建其它虚拟机的时候,也以上述虚拟机的磁盘为基础盘 ...

  3. 第十五章:Android 调用WebService(.net平台)

    什么是webservice? Web service是一个平台独立的,低耦合的,自包含的.基于可编程的web的应用程序,可使用开放的XML(标准通用标记语言下的一个子集)标准来描述.发布.发现.协调和 ...

  4. MVC中用Jpaginate分页 So easy!(兼容ie家族)

    看过几款分页插件,觉得Jpaginate比较简约,样式也比较容易的定制,而且体验也比较好,支持鼠标滑动效果.先上效果图: 整个过程很简单,只需要3步 一.引入相关样式和脚本: 1.MVC4中,用了Bu ...

  5. iOS YSMine 通用设置

    概述 我们在开发的过程中,经常需要重复的写个人中心设置的代码,很多情况下,我们都是通过if(indexPath.row)来判断操作以及要跳转的页面,这样的情况是非常不友好的,尤其是当我们需要调整显示顺 ...

  6. RequireJS源码初探

    前两天跟着叶小钗的博客,看了下RequireJS的源码,大体了解了其中的执行过程.不过在何时进行依赖项的加载,以及具体的代码在何处执行,还没有搞透彻,奈何能力不够,只能先记录一下了. RequireJ ...

  7. Why we need template on Django ?

    Let's create a simple website by django ... step01: django-admin startproject x01 step02: cd x01 ls ...

  8. PowerManager和WakeLock的操作步骤

    ①  PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);通过 Context.getSystemServ ...

  9. 【锁】Oracle锁系列

    [锁]Oracle锁系列 1  BLOG文档结构图 2  前言部分 2.1  导读和注意事项 各位技术爱好者,看完本文后,你可以掌握如下的技能,也可以学到一些其它你所不知道的知识,~O(∩_∩)O~: ...

  10. 详解Bootstrap按钮组件(二)

    按钮下拉菜单 按钮下拉菜单仅从外观上看和下拉菜单效果基本上是一样的.它们唯一的不同是外部容器div.dropdown换成了div.btn-group <div class="btn-g ...