]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/duration/requirements/sfinae_friendly_1.cc
1 // { dg-options "-std=c++11" }
4 // Copyright (C) 2012-2014 Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
21 #include <type_traits>
27 template<typename T
, typename
= typename
T::type
>
28 static std::true_type
test(int);
30 static std::false_type
test(...);
34 struct has_type
: public decltype(has_type_impl::test
<T
>(0))
37 template<typename T
, typename Expected
>
38 struct is_expected_type
: public std::is_same
<typename
T::type
, Expected
>
41 template<typename P1
, typename P2
>
42 struct and_
: public std::conditional
<P1::value
, P2
, std::false_type
>::type
45 template<typename T
, typename Expected
>
46 struct is_type
: public and_
<has_type
<T
>, is_expected_type
<T
, Expected
>>
51 typedef std::chrono::duration
<int, std::nano
> din
;
52 typedef std::chrono::duration
<double, std::nano
> ddn
;
53 typedef std::chrono::duration
<int, std::milli
> dim
;
55 static_assert(is_type
<std::common_type
<din
, din
>, din
>(), "");
56 static_assert(is_type
<std::common_type
<din
, din
, din
>, din
>(), "");
58 static_assert(is_type
<std::common_type
<din
, ddn
>, ddn
>(), "");
59 static_assert(is_type
<std::common_type
<din
, din
, ddn
>, ddn
>(), "");
60 static_assert(is_type
<std::common_type
<din
, ddn
>, ddn
>(), "");
61 static_assert(is_type
<std::common_type
<ddn
, din
, din
>, ddn
>(), "");
63 static_assert(!has_type
<std::common_type
<din
, int>>(), "");
64 static_assert(!has_type
<std::common_type
<din
, din
, int>>(), "");
65 static_assert(!has_type
<std::common_type
<int, din
, din
>>(), "");