iterator.pass.cpp 3.1 KB

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