// Copyright (C) 2020-2024 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 // . // { dg-do compile { target c++20 } } #include #include namespace chrono = std::chrono; static_assert( chrono::is_clock::value ); static_assert( chrono::is_clock_v ); static_assert( chrono::is_clock::value ); static_assert( chrono::is_clock_v ); static_assert( chrono::is_clock::value ); static_assert( chrono::is_clock_v ); static_assert(chrono::is_clock::value); static_assert(chrono::is_clock_v); // Clock will not use the specialization of is_clock template struct Clock : C { }; static_assert( chrono::is_clock>::value ); static_assert( chrono::is_clock_v> ); static_assert( chrono::is_clock>::value ); static_assert( chrono::is_clock_v> ); static_assert( chrono::is_clock>::value ); static_assert( chrono::is_clock_v> ); static_assert(chrono::is_clock>::value); static_assert(chrono::is_clock_v>); static_assert( chrono::is_clock<__gnu_test::slow_clock>::value ); static_assert( chrono::is_clock_v<__gnu_test::slow_clock> ); // Negative tests static_assert( ! chrono::is_clock::value ); static_assert( ! chrono::is_clock_v ); static_assert( ! chrono::is_clock::value ); static_assert( ! chrono::is_clock_v ); struct not_a_clock_1 { using rep = int; using period = std::ratio<4, 2>; using duration = chrono::duration; // different rep using time_point = chrono::time_point; static constexpr bool is_steady = false; static time_point now(); }; static_assert( ! chrono::is_clock::value ); static_assert( ! chrono::is_clock_v ); struct not_a_clock_2 { using rep = int; using period = int; // not a std::ratio using duration = chrono::duration; using time_point = chrono::time_point; static constexpr bool is_steady = false; static time_point now(); }; static_assert( ! chrono::is_clock::value ); static_assert( ! chrono::is_clock_v ); struct not_a_clock_3 { using rep = int; using period = std::ratio<1>; using duration = chrono::duration; // wrong duration: using time_point = chrono::time_point>; static constexpr bool is_steady = false; static time_point now(); }; static_assert( ! chrono::is_clock::value ); static_assert( ! chrono::is_clock_v ); struct not_a_clock_4 { using rep = int; using period = std::ratio<1>; using duration = chrono::duration; using time_point = chrono::time_point; static constexpr int is_steady = 0; // not a const bool static time_point now(); }; static_assert( ! chrono::is_clock::value ); static_assert( ! chrono::is_clock_v ); struct not_a_clock_5 { using rep = int; using period = std::ratio<1>; using duration = chrono::duration; using time_point = chrono::time_point; static constexpr bool is_steady = false; static int now(); // wrong return type }; static_assert( ! chrono::is_clock::value ); static_assert( ! chrono::is_clock_v ); struct not_a_clock_6 { using rep = int; using period = std::ratio<1>; using duration = chrono::duration; using time_point = chrono::time_point; const bool is_steady = false; // not static static time_point now(); }; static_assert( ! chrono::is_clock::value ); static_assert( ! chrono::is_clock_v );