zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    终于想起了博客园密码
    关于GCD的8题
    idea快捷键 ctrl + shift + f 失效解决方法
    前端和后端日期类型交互
    poi、easypoi和easyexcel的使用
    事务总结
    数据库cte的理解和使用
    mybatis 调用存储过程没有返回值
    postgresql 查询锁表并解锁
    tigase网络核心SockThread详解(十九)
  • 原文地址:https://www.cnblogs.com/rollenholt/p/2418275.html
Copyright © 2011-2022 走看看