]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/duration/requirements/sfinae_friendly_1.cc
Update copyright years in libstdc++-v3/
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / duration / requirements / sfinae_friendly_1.cc
1 // { dg-options "-std=c++11" }
2 // { dg-do compile }
3
4 // Copyright (C) 2012-2014 Free Software Foundation, Inc.
5 //
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)
10 // any later version.
11
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.
16
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/>.
20
21 #include <type_traits>
22 #include <chrono>
23
24 // Helper types:
25 struct has_type_impl
26 {
27 template<typename T, typename = typename T::type>
28 static std::true_type test(int);
29 template<typename>
30 static std::false_type test(...);
31 };
32
33 template<typename T>
34 struct has_type : public decltype(has_type_impl::test<T>(0))
35 {};
36
37 template<typename T, typename Expected>
38 struct is_expected_type : public std::is_same<typename T::type, Expected>
39 {};
40
41 template<typename P1, typename P2>
42 struct and_ : public std::conditional<P1::value, P2, std::false_type>::type
43 {};
44
45 template<typename T, typename Expected>
46 struct is_type : public and_<has_type<T>, is_expected_type<T, Expected>>
47 {};
48
49 // Inspection types:
50
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;
54
55 static_assert(is_type<std::common_type<din, din>, din>(), "");
56 static_assert(is_type<std::common_type<din, din, din>, din>(), "");
57
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>(), "");
62
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>>(), "");
66