iterator.pass.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. // UNSUPPORTED: c++98, c++03
  9. // <filesystem>
  10. // class path
  11. // template <class Source>
  12. // path(const Source& source);
  13. // template <class InputIterator>
  14. // path(InputIterator first, InputIterator last);
  15. #include "filesystem_include.hpp"
  16. #include <iterator>
  17. #include <type_traits>
  18. #include <cassert>
  19. #include "test_macros.h"
  20. #include "filesystem_test_helper.hpp"
  21. template <class It>
  22. std::reverse_iterator<It> mkRev(It it) {
  23. return std::reverse_iterator<It>(it);
  24. }
  25. void checkIteratorConcepts() {
  26. using namespace fs;
  27. using It = path::iterator;
  28. using Traits = std::iterator_traits<It>;
  29. ASSERT_SAME_TYPE(Traits::iterator_category, std::bidirectional_iterator_tag);
  30. ASSERT_SAME_TYPE(Traits::value_type, path);
  31. ASSERT_SAME_TYPE(Traits::pointer, path const*);
  32. ASSERT_SAME_TYPE(Traits::reference, path const&);
  33. {
  34. It it;
  35. ASSERT_SAME_TYPE(It&, decltype(++it));
  36. ASSERT_SAME_TYPE(It, decltype(it++));
  37. ASSERT_SAME_TYPE(It&, decltype(--it));
  38. ASSERT_SAME_TYPE(It, decltype(it--));
  39. ASSERT_SAME_TYPE(Traits::reference, decltype(*it));
  40. ASSERT_SAME_TYPE(Traits::pointer, decltype(it.operator->()));
  41. ASSERT_SAME_TYPE(std::string const&, decltype(it->native()));
  42. ASSERT_SAME_TYPE(bool, decltype(it == it));
  43. ASSERT_SAME_TYPE(bool, decltype(it != it));
  44. }
  45. {
  46. path const p;
  47. ASSERT_SAME_TYPE(It, decltype(p.begin()));
  48. ASSERT_SAME_TYPE(It, decltype(p.end()));
  49. assert(p.begin() == p.end());
  50. }
  51. }
  52. void checkBeginEndBasic() {
  53. using namespace fs;
  54. using It = path::iterator;
  55. {
  56. path const p;
  57. ASSERT_SAME_TYPE(It, decltype(p.begin()));
  58. ASSERT_SAME_TYPE(It, decltype(p.end()));
  59. assert(p.begin() == p.end());
  60. }
  61. {
  62. path const p("foo");
  63. It default_constructed;
  64. default_constructed = p.begin();
  65. assert(default_constructed == p.begin());
  66. assert(default_constructed != p.end());
  67. default_constructed = p.end();
  68. assert(default_constructed == p.end());
  69. assert(default_constructed != p.begin());
  70. }
  71. {
  72. path p("//root_name//first_dir////second_dir");
  73. const path expect[] = {"/", "root_name", "first_dir", "second_dir"};
  74. assert(checkCollectionsEqual(p.begin(), p.end(), std::begin(expect), std::end(expect)));
  75. assert(checkCollectionsEqualBackwards(p.begin(), p.end(), std::begin(expect), std::end(expect)));
  76. }
  77. {
  78. path p("////foo/bar/baz///");
  79. const path expect[] = {"/", "foo", "bar", "baz", ""};
  80. assert(checkCollectionsEqual(p.begin(), p.end(), std::begin(expect), std::end(expect)));
  81. assert(checkCollectionsEqualBackwards(p.begin(), p.end(), std::begin(expect), std::end(expect)));
  82. }
  83. }
  84. int main(int, char**) {
  85. using namespace fs;
  86. checkIteratorConcepts();
  87. checkBeginEndBasic(); // See path.decompose.pass.cpp for more tests.
  88. return 0;
  89. }