输出tuple和chrono的使用小例子
// move example
#include <iostream> // std::cout
#include<tuple>
#include<ratio>
#include<chrono>
using namespace std;
template<typename... Types>
ostream& operator<<(ostream& os, const tuple<Types...>& t1)
{
os << '[';
PRINT_TUPLE<0, sizeof...(Types), Types...>::print(os, t1);
os << ']';
return os;
}
template<int index, int max, typename... Types>
struct PRINT_TUPLE
{
static void print(ostream& os, const tuple<Types...>& t1)
{
os << get<index>(t1);
if(index<max-1)
os << ',';
PRINT_TUPLE<index + 1, sizeof...(Types), Types...>::print(os, t1);
}
};
template<int max, typename... Types>
struct PRINT_TUPLE<max,max,Types...>
{
static void print(ostream& os, const tuple<Types...>& t1)
{
}
};
int main() {
using namespace chrono;
using days_type=duration<int, ratio<60 * 60 * 24>>;
system_clock::time_point t1 = system_clock::now();
time_point<system_clock, days_type> today = time_point_cast<days_type>(system_clock::now());
cout << "距离1970年1月1日"<<today.time_since_epoch().count()<<"天" << endl;
system_clock::time_point tp = system_clock::now(); //typedef chrono::time_point<system_clock> system_clock::time_point;
tp += chrono::hours(24);
time_point<system_clock, days_type> tomorrow=time_point_cast<days_type>(tp);
cout << "距离1970年1月1日" << tomorrow.time_since_epoch().count() << "天" << endl;
system_clock::duration du(11); //typedef chrono::duration<rep, period> system_clock::duration;
cout <<"count:"<< du.count()<<",period:"<<system_clock::period::num<<'/'<<system_clock::period::den << endl;
nanoseconds dn=duration_cast<nanoseconds>(du);
cout <<"nanoseconds count:"<< dn.count()<< endl;
system_clock::time_point t2 = system_clock::now();
cout << "程序运行时间:" << duration_cast<microseconds>(t2 - t1).count() <<"微秒"<< endl;
system("pause");
return 0;
}
输出tuple和chrono的使用小例子的更多相关文章
- 试试 IEnumerable 的另外 6 个小例子
IEnumerable 接口是 C# 开发过程中非常重要的接口,对于其特性和用法的了解是十分必要的.本文将通过6个小例子,来熟悉一下其简单的用法. <!-- more --> 阅读建议 在 ...
- Runtime的几个小例子(含Demo)
一.什么是runtime(也就是所谓的“运行时”,因为是在运行时实现的.) 1.runtime是一套底层的c语言API(包括很多强大实用的c语言类型,c语言函数); [runti ...
- java连接mysql的一个小例子
想要用java 连接数据库,需要在classpath中加上jdbc的jar包路径 在eclipse中,Project的properties里面的java build path里面添加引用 连接成功的一 ...
- Java处理文件小例子--获取全国所有城市的坐标
需求:前端展示数据,全国城市的坐标
- 我的Android进阶之旅------>Android拍照小例子
今天简单的学习了一下android拍照的简单实现. 当然该程序是个小例子,非常简单,没有什么复杂的操作,但是可以学习到Android 拍照API流程. 1.在布局文件中添加一个 surfaceView ...
- Spring aop 小例子demo
由于最近的服务项目提供接口有一个需求,所有操作都必须检查操作的服务可用,所以感觉Aop特别适合实施.完成学习的小例子. 关于spring-Aop原理:http://m.oschina.net/blog ...
- JS的for循环小例子
1.输出1-100的和 var sum = 0; for(var i=1;i<=100;i++){ sum = sum + i; } document.write(sum); 2.输出1-100 ...
- c/c++ vector,map,set,智能指针,综合运用的小例子
标准库,智能指针,综合运用的小例子 功能说明:查询单词在文件中出现的次数,如果在同一行出现多次,只算一次. 比如查询单词:你好 输出的结果: 你好 出现了:2次 (行号 2)xxxxxxx 你好 (行 ...
- 一个有趣的小例子,带你入门协程模块-asyncio
一个有趣的小例子,带你入门协程模块-asyncio 上篇文章写了关于yield from的用法,简单的了解异步模式,[https://www.cnblogs.com/c-x-a/p/10106031. ...
随机推荐
- C语言基础:初级指针 分类: iOS学习 c语言基础 2015-06-10 21:50 30人阅读 评论(0) 收藏
指针:就是地址. & 取地址运算符 %p 打印地址占位符 int a=0; printf("%p ",&a); 指针变量:用来存放地址的变量 定义: ...
- Qt 获取组合键 键盘按住某键 鼠标组合实现
#include "mainwindow.h" #include <QDebug> #include <QKeyEvent> #include <QM ...
- Linux Framebuffer save as picture
/********************************************************************************* * Linux Framebuff ...
- 安装依赖库的方法-linux
前言 使用linux系统的过程中,项目可能需要用到各种依赖库或者工具包,本文对库或者包的安装方法进行概述. 具体方法 如何安装各种依赖库或者工具包:1)直接使用apt-get install进行安装, ...
- hdu2066 一个人的旅行 最短路
单源最短路裸题 #include<stdio.h> #include<string.h> #define min(a,b) (a)<(b)?a:b #define INF ...
- JQuery实时监控文本框字符变化
$(function(){ $('input[name="addr"]').on('input propertychange', function() { if ($('input ...
- MySQL--区分表名大小写
============================================================================ 在MySQL中,可以通过lower_case_ ...
- asp.net && javascript MD5加密
/* * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message * Digest Algorithm, as d ...
- QT内使用OpenCV
在QT内使用Opencv,调试了好久总是出问题. 開始在pro文件内进行了opencv的配置,然后就是不能识别#include包括文件,后来不知道什么原因.奇妙地 能够识别包括了. 但是,新的问题出现 ...
- 在CentOS和RHEL中配置SNMPv3
首先,使用yum安装必要的软件 [root@server ~]# yum install net-snmp-utils net-snmp-devel安装完成之后, 先停止snmpd,再创建具有只读属性 ...