]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/duration/requirements/sfinae_friendly_1.cc
1 // { dg-do compile { target c++11 } }
3 // Copyright (C) 2012-2018 Free Software Foundation, Inc.
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)
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 #include <type_traits>
26 template<typename T
, typename
= typename
T::type
>
27 static std::true_type
test(int);
29 static std::false_type
test(...);
33 struct has_type
: public decltype(has_type_impl::test
<T
>(0))
36 template<typename T
, typename Expected
>
37 struct is_expected_type
: public std::is_same
<typename
T::type
, Expected
>
40 template<typename P1
, typename P2
>
41 struct and_
: public std::conditional
<P1::value
, P2
, std::false_type
>::type
44 template<typename T
, typename Expected
>
45 struct is_type
: public and_
<has_type
<T
>, is_expected_type
<T
, Expected
>>
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
;
54 static_assert(is_type
<std::common_type
<din
, din
>, din
>(), "");
55 static_assert(is_type
<std::common_type
<din
, din
, din
>, din
>(), "");
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
>(), "");
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
>>(), "");