Remove dg-require-cstdint directive from tests
[official-gcc.git] / libstdc++-v3 / testsuite / 20_util / duration / cons / 2.cc
blob3f48f25f101e4fd78f64bae22ea2ae3bac16de45
1 // { dg-do run { target c++11 } }
3 // Copyright (C) 2008-2018 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
20 // 20.8.3 Class template duration [time.duration]
22 #include <chrono>
23 #include <type_traits>
24 #include <testsuite_hooks.h>
26 template<typename T>
27 struct type_emulator
29 type_emulator() : i(T(0)) { }
30 type_emulator(T j) : i(j) { }
31 type_emulator(const type_emulator& e) : i(e.i) { }
33 type_emulator& operator*=(type_emulator a)
34 { i *= a.i; return *this; }
36 type_emulator& operator+=(type_emulator a)
37 { i += a.i; return *this; }
39 operator T () { return i; }
40 T i;
43 template<typename T>
44 bool operator==(type_emulator<T> a, type_emulator<T> b)
45 { return a.i == b.i; }
47 template<typename T>
48 bool operator<(type_emulator<T> a, type_emulator<T> b)
49 { return a.i < b.i; }
51 template<typename T>
52 type_emulator<T> operator+(type_emulator<T> a, type_emulator<T> b)
53 { return a += b; }
55 template<typename T>
56 type_emulator<T> operator*(type_emulator<T> a, type_emulator<T> b)
57 { return a *= b; }
59 namespace std
61 template<typename T, typename U>
62 struct common_type<type_emulator<T>, U>
63 { typedef typename common_type<T,U>::type type; };
65 template<typename T, typename U>
66 struct common_type<U, type_emulator<T>>
67 { typedef typename common_type<U,T>::type type; };
69 template<typename T, typename U>
70 struct common_type<type_emulator<T>, type_emulator<U>>
71 { typedef typename common_type<T,U>::type type; };
73 namespace chrono
75 template<typename T>
76 struct treat_as_floating_point<type_emulator<T>>
77 : is_floating_point<T>
78 { };
82 typedef type_emulator<int> int_emulator;
83 typedef type_emulator<double> dbl_emulator;
85 // 20.8.3.1 duration constructors [time.duration.cons]
86 void
87 test01()
89 using namespace std::chrono;
91 duration<int> d0(3);
92 duration<int> d0_copy(d0);
93 VERIFY(d0_copy.count() == d0.count());
95 duration<int, std::milli> d1(5);
96 duration<int, std::micro> d1_copy(d1);
97 VERIFY(d1.count() * 1000 == d1_copy.count());
99 duration<double, std::micro> d2(8.0);
100 duration<double, std::milli> d2_copy(d2);
101 VERIFY(d2.count() == d2_copy.count() * 1000.0);
103 duration<int_emulator, std::milli> d3(5);
104 duration<int_emulator, std::micro> d3_copy(d3);
105 VERIFY(d3.count() * 1000 == d3_copy.count());
107 duration<dbl_emulator, std::micro> d4(5.0);
108 duration<dbl_emulator, std::milli> d4_copy(d4);
109 VERIFY(d4.count() == d4_copy.count() * dbl_emulator(1000.0));
113 main()
115 test01();
116 return 0;