1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 // UNSUPPORTED: c++03
10
11 // <filesystem>
12
13 // template <class Tp> struct __is_pathable
14
15 // [path.req]
16 // In addition to the requirements (5), function template parameters named
17 // `Source` shall be one of:
18 // * basic_string<_ECharT, _Traits, _Alloc>
19 // * InputIterator with a value_type of _ECharT
20 // * A character array, which points to a NTCTS after array-to-pointer decay.
21
22
23 #include "filesystem_include.h"
24 #include <type_traits>
25 #include <cassert>
26
27 #include "test_macros.h"
28 #include "test_iterators.h"
29 #include "min_allocator.h"
30 #include "constexpr_char_traits.h"
31
32 using fs::__is_pathable;
33
34 template <class Tp>
35 struct Identity { typedef Tp type; };
36
37 template <class Source>
38 Identity<Source> CheckSourceType(Source const&);
39
40 template <class Tp>
41 using GetSourceType = typename decltype(CheckSourceType(std::declval<Tp>()))::type;
42
43 template <class Tp, class Exp,
44 class ExpQual = typename std::remove_const<Exp>::type>
45 using CheckPass = std::is_same<ExpQual, GetSourceType<Tp>>;
46
47 template <class Source>
48 using CheckPassSource = std::integral_constant<bool,
49 CheckPass<Source&, Source>::value &&
50 CheckPass<Source const&, Source>::value &&
51 CheckPass<Source&&, Source>::value &&
52 CheckPass<Source const&&, Source>::value
53 >;
54
55 template <class CharT>
56 struct MakeTestType {
57 using value_type = CharT;
58 using string_type = std::basic_string<CharT>;
59 using string_type2 = std::basic_string<CharT, std::char_traits<CharT>, min_allocator<CharT>>;
60 using string_view_type = std::basic_string_view<CharT>;
61 using string_view_type2 = std::basic_string_view<CharT, constexpr_char_traits<CharT>>;
62 using cstr_type = CharT* const;
63 using const_cstr_type = const CharT*;
64 using array_type = CharT[25];
65 using const_array_type = const CharT[25];
66 using iter_type = cpp17_input_iterator<CharT*>;
67 using bad_iter_type = cpp17_input_iterator<signed char*>;
68
69 template <class TestT>
AssertPathableMakeTestType70 static void AssertPathable() {
71 static_assert(__is_pathable<TestT>::value, "");
72 static_assert(CheckPassSource<TestT>::value, "cannot pass as Source const&");
73 ASSERT_SAME_TYPE(CharT, typename __is_pathable<TestT>::__char_type);
74 }
75
76 template <class TestT>
AssertNotPathableMakeTestType77 static void AssertNotPathable() {
78 static_assert(!__is_pathable<TestT>::value, "");
79 }
80
TestMakeTestType81 static void Test() {
82 AssertPathable<string_type>();
83 AssertPathable<string_type2>();
84 AssertPathable<string_view_type>();
85 AssertPathable<string_view_type2>();
86 AssertPathable<cstr_type>();
87 AssertPathable<const_cstr_type>();
88 AssertPathable<array_type>();
89 AssertPathable<const_array_type>();
90 AssertPathable<iter_type>();
91
92 AssertNotPathable<CharT>();
93 AssertNotPathable<bad_iter_type>();
94 AssertNotPathable<signed char*>();
95 }
96 };
97
main(int,char **)98 int main(int, char**) {
99 MakeTestType<char>::Test();
100 MakeTestType<wchar_t>::Test();
101 MakeTestType<char16_t>::Test();
102 MakeTestType<char32_t>::Test();
103
104 return 0;
105 }
106