]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/libcxx/experimental/filesystem/class.path/path.req/is_pathable.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / libcxx / experimental / filesystem / class.path / path.req / is_pathable.pass.cpp
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // UNSUPPORTED: c++98, c++03
11
12 // <experimental/filesystem>
13
14 // template <class Tp> struct __is_pathable
15
16 // [path.req]
17 // In addition to the requirements (5), function template parameters named
18 // `Source` shall be one of:
19 // * basic_string<_ECharT, _Traits, _Alloc>
20 // * InputIterator with a value_type of _ECharT
21 // * A character array, which points to a NTCTS after array-to-pointer decay.
22
23
24 #include <experimental/filesystem>
25 #include <type_traits>
26 #include <cassert>
27
28 #include "test_macros.h"
29 #include "test_iterators.h"
30 #include "min_allocator.h"
31 #include "constexpr_char_traits.hpp"
32
33 namespace fs = std::experimental::filesystem;
34
35 using fs::__is_pathable;
36
37 template <class Tp>
38 struct Identity { typedef Tp type; };
39
40 template <class Source>
41 Identity<Source> CheckSourceType(Source const&);
42
43 template <class Tp>
44 using GetSourceType = typename decltype(CheckSourceType(std::declval<Tp>()))::type;
45
46 template <class Tp, class Exp,
47           class ExpQual = typename std::remove_const<Exp>::type>
48 using CheckPass = std::is_same<ExpQual, GetSourceType<Tp>>;
49
50 template <class Source>
51 using CheckPassSource = std::integral_constant<bool,
52         CheckPass<Source&,        Source>::value &&
53         CheckPass<Source const&,  Source>::value &&
54         CheckPass<Source&&,       Source>::value &&
55         CheckPass<Source const&&, Source>::value
56   >;
57
58 template <class CharT>
59 struct MakeTestType {
60   using value_type = CharT;
61   using string_type = std::basic_string<CharT>;
62   using string_type2 = std::basic_string<CharT, std::char_traits<CharT>, min_allocator<CharT>>;
63   using string_view_type = std::basic_string_view<CharT>;
64   using string_view_type2 = std::basic_string_view<CharT, constexpr_char_traits<CharT>>;
65   using cstr_type = CharT* const;
66   using const_cstr_type = const CharT*;
67   using array_type = CharT[25];
68   using const_array_type = const CharT[25];
69   using iter_type = input_iterator<CharT*>;
70   using bad_iter_type = input_iterator<signed char*>;
71
72   template <class TestT>
73   static void AssertPathable() {
74     static_assert(__is_pathable<TestT>::value, "");
75     static_assert(CheckPassSource<TestT>::value, "cannot pass as Source const&");
76     ASSERT_SAME_TYPE(CharT, typename __is_pathable<TestT>::__char_type);
77   }
78
79   template <class TestT>
80   static void AssertNotPathable() {
81     static_assert(!__is_pathable<TestT>::value, "");
82   }
83
84   static void Test() {
85     AssertPathable<string_type>();
86     AssertPathable<string_type2>();
87     AssertPathable<string_view_type>();
88     AssertPathable<string_view_type2>();
89     AssertPathable<cstr_type>();
90     AssertPathable<const_cstr_type>();
91     AssertPathable<array_type>();
92     AssertPathable<const_array_type>();
93     AssertPathable<iter_type>();
94
95     AssertNotPathable<CharT>();
96     AssertNotPathable<bad_iter_type>();
97     AssertNotPathable<signed char*>();
98   }
99 };
100
101 int main() {
102   MakeTestType<char>::Test();
103   MakeTestType<wchar_t>::Test();
104   MakeTestType<char16_t>::Test();
105   MakeTestType<char32_t>::Test();
106 }