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 // class path 14 15 // template <class Source> 16 // path(const Source& source); 17 // template <class InputIterator> 18 // path(InputIterator first, InputIterator last); 19 20 21 #include "filesystem_include.h" 22 #include <cassert> 23 #include <iterator> 24 #include <type_traits> 25 26 #include "test_macros.h" 27 #include "filesystem_test_helper.h" 28 29 void checkIteratorConcepts() { 30 using namespace fs; 31 using It = path::iterator; 32 using Traits = std::iterator_traits<It>; 33 ASSERT_SAME_TYPE(path::const_iterator, It); 34 #if TEST_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS) 35 static_assert(std::bidirectional_iterator<It>); 36 #endif 37 ASSERT_SAME_TYPE(Traits::value_type, path); 38 LIBCPP_STATIC_ASSERT(std::is_same<Traits::iterator_category, std::input_iterator_tag>::value, ""); 39 LIBCPP_STATIC_ASSERT(std::is_same<Traits::pointer, path const*>::value, ""); 40 LIBCPP_STATIC_ASSERT(std::is_same<Traits::reference, path>::value, ""); 41 { 42 It it; 43 ASSERT_SAME_TYPE(It&, decltype(++it)); 44 ASSERT_SAME_TYPE(It, decltype(it++)); 45 ASSERT_SAME_TYPE(It&, decltype(--it)); 46 ASSERT_SAME_TYPE(It, decltype(it--)); 47 ASSERT_SAME_TYPE(Traits::reference, decltype(*it)); 48 ASSERT_SAME_TYPE(Traits::pointer, decltype(it.operator->())); 49 #ifdef _WIN32 50 ASSERT_SAME_TYPE(std::wstring const&, decltype(it->native())); 51 #else 52 ASSERT_SAME_TYPE(std::string const&, decltype(it->native())); 53 #endif 54 ASSERT_SAME_TYPE(bool, decltype(it == it)); 55 ASSERT_SAME_TYPE(bool, decltype(it != it)); 56 } 57 { 58 path const p; 59 ASSERT_SAME_TYPE(It, decltype(p.begin())); 60 ASSERT_SAME_TYPE(It, decltype(p.end())); 61 assert(p.begin() == p.end()); 62 } 63 } 64 65 void checkBeginEndBasic() { 66 using namespace fs; 67 using It = path::iterator; 68 { 69 path const p; 70 ASSERT_SAME_TYPE(It, decltype(p.begin())); 71 ASSERT_SAME_TYPE(It, decltype(p.end())); 72 assert(p.begin() == p.end()); 73 } 74 { 75 path const p("foo"); 76 It default_constructed; 77 default_constructed = p.begin(); 78 assert(default_constructed == p.begin()); 79 assert(default_constructed != p.end()); 80 default_constructed = p.end(); 81 assert(default_constructed == p.end()); 82 assert(default_constructed != p.begin()); 83 } 84 { 85 path p("//root_name//first_dir////second_dir"); 86 #ifdef _WIN32 87 const path expect[] = {"//root_name", "/", "first_dir", "second_dir"}; 88 #else 89 const path expect[] = {"/", "root_name", "first_dir", "second_dir"}; 90 #endif 91 assert(checkCollectionsEqual(p.begin(), p.end(), std::begin(expect), std::end(expect))); 92 assert(checkCollectionsEqualBackwards(p.begin(), p.end(), std::begin(expect), std::end(expect))); 93 } 94 { 95 path p("////foo/bar/baz///"); 96 const path expect[] = {"/", "foo", "bar", "baz", ""}; 97 assert(checkCollectionsEqual(p.begin(), p.end(), std::begin(expect), std::end(expect))); 98 assert(checkCollectionsEqualBackwards(p.begin(), p.end(), std::begin(expect), std::end(expect))); 99 } 100 } 101 102 int main(int, char**) { 103 using namespace fs; 104 checkIteratorConcepts(); 105 checkBeginEndBasic(); // See path.decompose.pass.cpp for more tests. 106 107 return 0; 108 } 109