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 ...
随机推荐
- Keil的标题“礦ision3" 的改变(转)
MDK 的标题显示成 “礦ision3",前面的这个不是u而是一个希腊字母“缪”,在中文显示中出现问题,半个汉字. 可以使用如下方法取消. 一: 光标问题 Keil uv3 中会出现光标定位 ...
- 理解 Soap
http://www.cnblogs.com/yhuang/archive/2012/04/04/share_storm.html 自己也写了下: using System; using System ...
- 动手写一个Remoting接口测试工具(附源码下载)
基于.NET开发分布式系统,经常用到Remoting技术.在测试驱动开发流行的今天,如果针对分布式系统中的每个Remoting接口的每个方法都要写详细的测试脚本,无疑非常浪费时间.所以,我想写一个能自 ...
- 微软BI 之SSRS 系列 - 如何设置页标题重复
开篇介绍 这个问题大家经常碰到,特意写一下如何解决这个小问题. 问题 默认情况下当报表超过一定的高度会自动分成多页. 第二页默认是看不到标题的. 解决方法 2012版本下在 Column Groups ...
- 用SQL语句断开某个数据库的所有活动连接
每次一执行完一个数据库脚本,想要做一些别的操作的时候(比如还原数据库),老是有数据库活动连接,烦不胜烦(如下图所示). 下面给出一种删除数据库活动连接的方式.将下面代码段中的“--修改一下”处的数据库 ...
- [C++] 行程编码C++代码
#include<iostream> #include<string.h> #include<string> #include<cstring> #in ...
- SignalR 简单示例
一.什么是 SignalR ASP.NET SignalR is a library for ASP.NET developers that simplifies the process of add ...
- webApp 阅读器项目实践
这是一个webApp 阅读器的项目,是慕课网的老师讲授的一个实战,先给出项目源码在GitHub的地址:https://github.com/yulifromchina/MobileWebReader. ...
- SSL在https和MySQL中的原理思考
之前对HTTPS通信过程有过了解,HTTPS是应用HTTP协议使用SSL加密的版本,在TCP和HTTP之间增加SSL协议.通过握手阶段认证双方身份,协商对称秘钥对通信信息进行加密.此处只描述常用的服务 ...
- Mule ESB 社区版 企业版 资源下载 包含3.5和3.6
很多的资源官方已经没有提供下载了,我将资源上传到网盘,供大家下载和收藏 AnypointStudio-for-win-32bit-5.0.2-201502251307.ziphttp://pan.ba ...