summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/std/time/traits/is_clock.cc
blob: 85f118253c3781cef0858e2409ab738ad1efd067 (plain)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Copyright (C) 2020 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3.  If not see
// <http://www.gnu.org/licenses/>.

// { dg-options "-std=gnu++2a" }
// { dg-do compile { target c++2a } }

#include <chrono>
#include <slow_clock.h>

namespace chrono = std::chrono;

static_assert( chrono::is_clock<chrono::system_clock>::value );
static_assert( chrono::is_clock_v<chrono::system_clock> );

static_assert( chrono::is_clock<chrono::high_resolution_clock>::value );
static_assert( chrono::is_clock_v<chrono::high_resolution_clock> );

static_assert( chrono::is_clock<chrono::steady_clock>::value );
static_assert( chrono::is_clock_v<chrono::steady_clock> );

static_assert(chrono::is_clock<chrono::file_clock>::value);
static_assert(chrono::is_clock_v<chrono::file_clock>);

static_assert( chrono::is_clock<__gnu_test::slow_clock>::value );
static_assert( chrono::is_clock_v<__gnu_test::slow_clock> );

static_assert( ! chrono::is_clock<int>::value );
static_assert( ! chrono::is_clock_v<int> );

static_assert( ! chrono::is_clock<void>::value );
static_assert( ! chrono::is_clock_v<void> );

struct not_a_clock_1
{
  using rep = int;
  using period = std::ratio<4, 2>;
  using duration = chrono::duration<long, period>; // different rep
  using time_point = chrono::time_point<not_a_clock_1>;
  static constexpr bool is_steady = false;
  static time_point now();
};

static_assert( ! chrono::is_clock<not_a_clock_1>::value );
static_assert( ! chrono::is_clock_v<not_a_clock_1> );

struct not_a_clock_2
{
  using rep = int;
  using period = int; // not a std::ratio
  using duration = chrono::duration<rep>;
  using time_point = chrono::time_point<not_a_clock_2>;
  static constexpr bool is_steady = false;
  static time_point now();
};

static_assert( ! chrono::is_clock<not_a_clock_2>::value );
static_assert( ! chrono::is_clock_v<not_a_clock_2> );

struct not_a_clock_3
{
  using rep = int;
  using period = std::ratio<1>;
  using duration = chrono::duration<rep>;
  // wrong duration:
  using time_point = chrono::time_point<not_a_clock_3, chrono::duration<long>>;
  static constexpr bool is_steady = false;
  static time_point now();
};

static_assert( ! chrono::is_clock<not_a_clock_3>::value );
static_assert( ! chrono::is_clock_v<not_a_clock_3> );

struct not_a_clock_4
{
  using rep = int;
  using period = std::ratio<1>;
  using duration = chrono::duration<rep>;
  using time_point = chrono::time_point<not_a_clock_4>;
  static constexpr int is_steady = 0; // not a const bool
  static time_point now();
};

static_assert( ! chrono::is_clock<not_a_clock_4>::value );
static_assert( ! chrono::is_clock_v<not_a_clock_4> );

struct not_a_clock_5
{
  using rep = int;
  using period = std::ratio<1>;
  using duration = chrono::duration<rep>;
  using time_point = chrono::time_point<not_a_clock_5>;
  static constexpr bool is_steady = false;
  static int now(); // wrong return type
};

static_assert( ! chrono::is_clock<not_a_clock_5>::value );
static_assert( ! chrono::is_clock_v<not_a_clock_5> );

struct not_a_clock_6
{
  using rep = int;
  using period = std::ratio<1>;
  using duration = chrono::duration<rep>;
  using time_point = chrono::time_point<not_a_clock_6>;
  const bool is_steady = false; // not static
  static time_point now();
};

static_assert( ! chrono::is_clock<not_a_clock_6>::value );
static_assert( ! chrono::is_clock_v<not_a_clock_6> );