File: test_10631.cpp

package info (click to toggle)
boost1.90 1.90.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 593,120 kB
  • sloc: cpp: 4,190,908; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,774; makefile: 1,161; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (61 lines) | stat: -rw-r--r-- 1,930 bytes parent folder | download | duplicates (18)
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
56
57
58
59
60
61
//  Copyright 2015 Vicente J. Botet Escriba
//  Distributed under the Boost Software License, Version 1.0.
//  See http://www.boost.org/LICENSE_1_0.txt
//  See http://www.boost.org/libs/chrono for documentation.

#define BOOST_CHRONO_VERION 2
#include <iostream>
#include <boost/chrono/chrono.hpp>
#include <boost/chrono/chrono_io.hpp>

// a custom clock
// here based on boost's own system_clock
class MyMillenniumClock
{
public:
  typedef boost::chrono::system_clock::rep rep;
  typedef boost::chrono::system_clock::period period;
  typedef boost::chrono::duration<rep, period> duration;
  typedef boost::chrono::time_point<MyMillenniumClock> time_point;

  BOOST_STATIC_CONSTEXPR bool is_steady = boost::chrono::system_clock::is_steady;

public:
  /// Returns a time_point representing the current value of the clock.
  static time_point now() {
    return time_point(boost::chrono::system_clock::now().time_since_epoch() - boost::chrono::hours(30*365));
  }
};


namespace boost
{
  namespace chrono
  {
    template <class CharT>
    struct clock_string<MyMillenniumClock, CharT>
    {
      static std::basic_string<CharT> name() {
        static const CharT a[] = {'M', 'y', 'M', 'i', 'l', 'l', 'e', 'n', 'n', 'i', 'u', 'm', 'C', 'l', 'o', 'c', 'k'};
        return std::basic_string<CharT>(a, a + sizeof(a)/sizeof(a[0]));
      }
      static std::basic_string<CharT> since() {
        static const CharT a[] = {' ', 's', 'i', 'n', 'c', 'e', ' ', 'y', 'e', 'a', 'r', ' ', '2', 'k'};
        return std::basic_string<CharT>(a, a + sizeof(a)/sizeof(a[0]));
      }
    };
  }
}

template <typename CharT, typename TPUFacet>
std::basic_string<CharT> get_epoch_custom(MyMillenniumClock, TPUFacet&)
{
  return boost::chrono::clock_string<MyMillenniumClock,CharT>::since();
}

int main()
{
    std::cout << boost::chrono::steady_clock::now() << std::endl;
    std::cout << MyMillenniumClock::now() << std::endl;
    return 0;
}