输出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. ...
随机推荐
- PostgreSQL11.2 configure卡住 checking for DocBook XML V4.2
在PG11.2的数据库编译过程中,卡在了“checking for DocBook XML V4.2”,不动,需要安装docbook才可以. 需要安装: yum install docbook-dtd ...
- SSH 获取GET/POST参数
在做项目的API通知接口的时候,发现在SSH框架中无法获取到对方服务器发来的异步通知信息.最后排查到的原因可能是struts2对HttpServletRequest进行了二次处理,那么该如何拿到pos ...
- 【linux基础】core dump debug
1.check core dump; ulimit -c or ulimit -a nvidia@tegra-ubuntu:~$ ulimit -a core data seg size (kbyte ...
- [LeetCode&Python] Problem 617. Merge Two Binary Trees
Given two binary trees and imagine that when you put one of them to cover the other, some nodes of t ...
- ElasticSearch(三):ES单机版本基本操作之删除,修改,插入
1. 创建索引 1.1 直接创建索引 可以直接使用head插件创建索引,指定分片数和备份数即可.如下图: 1.2 创建结构化索引 上图创建的索引,点开索引信息,mapping是空的,表示该索引的字段并 ...
- com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. 问题解决方法
一.问题 今天用mybatis连接数据库时出现了如下错误: com.mysql.cj.exceptions.InvalidConnectionAttributeException: The serve ...
- 【java规则引擎】《Drools7.0.0.Final规则引擎教程》第4章 4.4 LHS简介&Pattern
LHS简介 在规则文件组成章节,我们已经了解了LHS的基本使用说明.LHS是规则条件部分的统称,由0个或多个条件元素组成.前面我们已经提到,如果没有条件元素那么默认就是true. 没有条件元素,官方示 ...
- Git冲突和解决冲突
1.产生冲突原因 产生:多个开发者同时使用或者操作git中的同一个文件,最后在依次提交和push的时候,第一个操作的是可以正常提交的,而之后的开发者想要执行pull(拉)和pull(push)操作的时 ...
- MySQL--常见ALTER TABLE 操作
##================================## ## 修改表的存储引擎 ## SHOW TABLE STATUS LIKE 'TB_001' \G; ALTER TABLE ...
- loopback v4 特性
loopback 是一个api 服务框架,挺方便的,同时也已经演进了好几代了v4 有一些新功能的 支持 新特性 基于typescript/es2017 开发 openapi 驱动的rest api 开 ...