-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.h
55 lines (45 loc) · 1011 Bytes
/
common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// (c) 2013 Andrey Upadyshev aka oliora <[email protected]>.
// File released to public domain.
#pragma once
#ifdef WIN32
#define WINVER 0x0600
#define WIN32_LEAN_AND_MEAN
#include "Windows.h"
#endif
#include <iostream>
#include <sstream>
#include <iomanip>
#include <chrono>
#include <boost/chrono/chrono.hpp>
#include <mutex>
namespace chrono_test
{
template<class _Rep, class _Period>
double seconds(const std::chrono::duration<_Rep, _Period>& d)
{
return std::chrono::nanoseconds(d).count() / 1E9;
}
template<class _Rep, class _Period>
double seconds(const boost::chrono::duration<_Rep, _Period>& d)
{
return boost::chrono::nanoseconds(d).count() / 1E9;
}
class synced_cout
{
public:
template<typename T>
synced_cout& operator<< (const T& t)
{
m_buf << t;
return *this;
}
~synced_cout()
{
static std::mutex m;
std::lock_guard<std::mutex> lock(m);
std::cout << m_buf.str();
}
private:
std::stringstream m_buf;
};
}