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

  • 相关阅读:
    专题实验 Toad 用户的创建与管理( 包括 role 等 )
    专题实验 字符集(全球化支持)
    Toad 所有 菜单说明(太多)
    java 调试
    java 基础数据结构
    HeadFirst Jsp 09 (JSTL)
    HeadFirst jsp 08 无脚本JSP
    14 多线程
    Struts2配置
    Struts框架搭建时所遇到的问题
  • 原文地址:https://www.cnblogs.com/rollenholt/p/2418275.html
Copyright © 2011-2022 走看看