| 1 |
// { dg-do compile { target c++11 } } |
| 2 |
|
| 3 |
// Copyright (C) 2012-2025 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. |
| 10 |
|
| 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. |
| 15 |
|
| 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/>. |
| 19 |
|
| 20 |
#include <type_traits> |
| 21 |
#include <chrono> |
| 22 |
|
| 23 |
// Helper types: |
| 24 |
struct has_type_impl |
| 25 |
{ |
| 26 |
template<typename T, typename = typename T::type> |
| 27 |
static std::true_type test(int); |
| 28 |
template<typename> |
| 29 |
static std::false_type test(...); |
| 30 |
}; |
| 31 |
|
| 32 |
template<typename T> |
| 33 |
struct has_type : public decltype(has_type_impl::test<T>(0)) |
| 34 |
{}; |
| 35 |
|
| 36 |
template<typename T, typename Expected> |
| 37 |
struct is_expected_type : public std::is_same<typename T::type, Expected> |
| 38 |
{}; |
| 39 |
|
| 40 |
template<typename P1, typename P2> |
| 41 |
struct and_ : public std::conditional<P1::value, P2, std::false_type>::type |
| 42 |
{}; |
| 43 |
|
| 44 |
template<typename T, typename Expected> |
| 45 |
struct is_type : public and_<has_type<T>, is_expected_type<T, Expected>> |
| 46 |
{}; |
| 47 |
|
| 48 |
// Inspection types: |
| 49 |
|
| 50 |
typedef std::chrono::duration<int, std::nano> din; |
| 51 |
typedef std::chrono::duration<double, std::nano> ddn; |
| 52 |
typedef std::chrono::duration<int, std::milli> dim; |
| 53 |
|
| 54 |
static_assert(is_type<std::common_type<din, din>, din>(), ""); |
| 55 |
static_assert(is_type<std::common_type<din, din, din>, din>(), ""); |
| 56 |
|
| 57 |
static_assert(is_type<std::common_type<din, ddn>, ddn>(), ""); |
| 58 |
static_assert(is_type<std::common_type<din, din, ddn>, ddn>(), ""); |
| 59 |
static_assert(is_type<std::common_type<din, ddn>, ddn>(), ""); |
| 60 |
static_assert(is_type<std::common_type<ddn, din, din>, ddn>(), ""); |
| 61 |
|
| 62 |
static_assert(!has_type<std::common_type<din, int>>(), ""); |
| 63 |
static_assert(!has_type<std::common_type<din, din, int>>(), ""); |
| 64 |
static_assert(!has_type<std::common_type<int, din, din>>(), ""); |
| 65 |
|