is_pathable.pass.cpp (3265B)
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 // <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 "filesystem_include.hpp" 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 using fs::__is_pathable; 34 35 template <class Tp> 36 struct Identity { typedef Tp type; }; 37 38 template <class Source> 39 Identity<Source> CheckSourceType(Source const&); 40 41 template <class Tp> 42 using GetSourceType = typename decltype(CheckSourceType(std::declval<Tp>()))::type; 43 44 template <class Tp, class Exp, 45 class ExpQual = typename std::remove_const<Exp>::type> 46 using CheckPass = std::is_same<ExpQual, GetSourceType<Tp>>; 47 48 template <class Source> 49 using CheckPassSource = std::integral_constant<bool, 50 CheckPass<Source&, Source>::value && 51 CheckPass<Source const&, Source>::value && 52 CheckPass<Source&&, Source>::value && 53 CheckPass<Source const&&, Source>::value 54 >; 55 56 template <class CharT> 57 struct MakeTestType { 58 using value_type = CharT; 59 using string_type = std::basic_string<CharT>; 60 using string_type2 = std::basic_string<CharT, std::char_traits<CharT>, min_allocator<CharT>>; 61 using string_view_type = std::basic_string_view<CharT>; 62 using string_view_type2 = std::basic_string_view<CharT, constexpr_char_traits<CharT>>; 63 using cstr_type = CharT* const; 64 using const_cstr_type = const CharT*; 65 using array_type = CharT[25]; 66 using const_array_type = const CharT[25]; 67 using iter_type = input_iterator<CharT*>; 68 using bad_iter_type = input_iterator<signed char*>; 69 70 template <class TestT> 71 static void AssertPathable() { 72 static_assert(__is_pathable<TestT>::value, ""); 73 static_assert(CheckPassSource<TestT>::value, "cannot pass as Source const&"); 74 ASSERT_SAME_TYPE(CharT, typename __is_pathable<TestT>::__char_type); 75 } 76 77 template <class TestT> 78 static void AssertNotPathable() { 79 static_assert(!__is_pathable<TestT>::value, ""); 80 } 81 82 static void Test() { 83 AssertPathable<string_type>(); 84 AssertPathable<string_type2>(); 85 AssertPathable<string_view_type>(); 86 AssertPathable<string_view_type2>(); 87 AssertPathable<cstr_type>(); 88 AssertPathable<const_cstr_type>(); 89 AssertPathable<array_type>(); 90 AssertPathable<const_array_type>(); 91 AssertPathable<iter_type>(); 92 93 AssertNotPathable<CharT>(); 94 AssertNotPathable<bad_iter_type>(); 95 AssertNotPathable<signed char*>(); 96 } 97 }; 98 99 int main() { 100 MakeTestType<char>::Test(); 101 MakeTestType<wchar_t>::Test(); 102 MakeTestType<char16_t>::Test(); 103 MakeTestType<char32_t>::Test(); 104 }