Debian Codegraph @

libstdc++-v3/testsuite/20_util/duration/cons/dr1177.cc

raw
1 // Copyright (C) 2017-2025 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
8
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
17
18 // { dg-do compile { target c++11 } }
19
20 #include <chrono>
21 #include <type_traits>
22
23 using namespace std;
24 using namespace std::chrono;
25
26 // DR 1177
27 static_assert(is_constructible<duration<float>, duration<double>>{},
28 "can convert duration with one floating point rep to another");
29 static_assert(is_constructible<duration<float>, duration<int>>{},
30 "can convert duration with integral rep to one with floating point rep");
31 static_assert(!is_constructible<duration<int>, duration<float>>{},
32 "cannot convert duration with floating point rep to one with integral rep");
33 static_assert(is_constructible<duration<int>, duration<long>>{},
34 "can convert duration with one integral rep to another");
35
36 static_assert(!is_constructible<duration<int>, duration<int, ratio<2,3>>>{},
37 "cannot convert duration to one with different period");
38 static_assert(is_constructible<duration<float>, duration<int, ratio<2,3>>>{},
39 "... unless the result type has a floating-point representation");
40 static_assert(is_constructible<duration<int, ratio<1,3>>, duration<int>>{},
41 "... or the original's period is a multiple of the result's period");