Boost–progress_timer

简介:

progress_timer继承自timer,但是精度为2,为了扩展精度,我们自己实现一个类,代码如下:

#include <iostream>
#include<boost/progress.hpp>
#include <boost/static_assert.hpp>
using namespace std;
using namespace boost;


template<int N=2>
class new_progress_timer :public timer{
public:
	new_progress_timer(ostream &os=cout):m_os(os){
		
		BOOST_STATIC_ASSERT(N>=0&&NULL<=10);
	}
	~new_progress_timer(){

		try{
			istream::fmtflags old_flags=m_os.setf(istream::fixed,istream::floatfield);
			streamsize old_prec=m_os.precision(N);

			//输出时间
			m_os<<elapsed()<<"s\n"<<endl;

			//恢复流的状态
			m_os.flags(old_flags);
			m_os.precision(old_prec);
		}catch(...){
			//do nothing
		}
	}
private: 
	ostream &m_os;
};

int _tmain(int argc, _TCHAR* argv[])
{	
	new_progress_timer<10> t;

	//cout<<t.elapsed(); 这里不需要亲自调用,当超过t的作用域的时候自动调用
	return 0;
}

image

目录
相关文章
|
3月前
|
编解码 安全 Linux
Clock sources, Clock events, sched_clock() and delay timers【ChatGPT】
Clock sources, Clock events, sched_clock() and delay timers【ChatGPT】
|
6月前
|
Python
【ERROR】asyncio.run(main())报错:RuntimeError: Event loop is closed
【ERROR】asyncio.run(main())报错:RuntimeError: Event loop is closed
134 0
|
前端开发
The following tasks did not complete: first Did you forget to signal async completion?
The following tasks did not complete: first Did you forget to signal async completion?
|
内存技术
Egret的TimerEvent.TIMER和Event.ENTER_FRAME的区别
Egret的TimerEvent.TIMER和Event.ENTER_FRAME的区别
76 0
|
PHP
swoole,swoole_timer_tick() must be callable, array given 报错异常
easyswoole框架内部交流后也说明这个问题是由于swoole版本变动,很早以前就在新版做了兼容(将intervalCheck改为public方法)
187 0
|
C++
boost之signal的使用
boost是C++的一个扩展库,被称为C++准标准库,里面的组件很丰富,并且引用方便,85%的组件只需要引用头文件即可使用。在嵌入式系统也可以很方便的使用,这里介绍一下signal的使用,有点类似Qt里的信号槽。 可以接收静态函数、类成员函数、labmda表达式。 下面这个是使用signal封装的一个事件注册处理模板,使用起来还是很方便的。
135 0
|
Python
may have been in progress in another thread when fork() was called.
may have been in progress in another thread when fork() was called.
141 0
may have been in progress in another thread when fork() was called.