find_first_of.pass.cpp 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. // <algorithm>
  10. // template<InputIterator Iter1, ForwardIterator Iter2>
  11. // requires HasEqualTo<Iter1::value_type, Iter2::value_type>
  12. // constexpr Iter1 // constexpr after C++17
  13. // find_first_of(Iter1 first1, Iter1 last1, Iter2 first2, Iter2 last2);
  14. #include <algorithm>
  15. #include <cassert>
  16. #include "test_macros.h"
  17. #include "test_iterators.h"
  18. #if TEST_STD_VER > 17
  19. TEST_CONSTEXPR bool test_constexpr() {
  20. int ia[] = {1, 2, 3};
  21. int ib[] = {7, 8, 9};
  22. int ic[] = {0, 1, 2, 3, 4, 5, 0, 1, 2, 3};
  23. typedef forward_iterator<int*> FI;
  24. typedef bidirectional_iterator<int*> BI;
  25. typedef random_access_iterator<int*> RI;
  26. return (std::find_first_of(FI(std::begin(ic)), FI(std::end(ic)), FI(std::begin(ia)), FI(std::end(ia))) == FI(ic+1))
  27. && (std::find_first_of(FI(std::begin(ic)), FI(std::end(ic)), FI(std::begin(ib)), FI(std::end(ib))) == FI(std::end(ic)))
  28. && (std::find_first_of(BI(std::begin(ic)), BI(std::end(ic)), BI(std::begin(ia)), BI(std::end(ia))) == BI(ic+1))
  29. && (std::find_first_of(BI(std::begin(ic)), BI(std::end(ic)), BI(std::begin(ib)), BI(std::end(ib))) == BI(std::end(ic)))
  30. && (std::find_first_of(RI(std::begin(ic)), RI(std::end(ic)), RI(std::begin(ia)), RI(std::end(ia))) == RI(ic+1))
  31. && (std::find_first_of(RI(std::begin(ic)), RI(std::end(ic)), RI(std::begin(ib)), RI(std::end(ib))) == RI(std::end(ic)))
  32. ;
  33. }
  34. #endif
  35. int main()
  36. {
  37. int ia[] = {0, 1, 2, 3, 0, 1, 2, 3};
  38. const unsigned sa = sizeof(ia)/sizeof(ia[0]);
  39. int ib[] = {1, 3, 5, 7};
  40. const unsigned sb = sizeof(ib)/sizeof(ib[0]);
  41. assert(std::find_first_of(input_iterator<const int*>(ia),
  42. input_iterator<const int*>(ia + sa),
  43. forward_iterator<const int*>(ib),
  44. forward_iterator<const int*>(ib + sb)) ==
  45. input_iterator<const int*>(ia+1));
  46. int ic[] = {7};
  47. assert(std::find_first_of(input_iterator<const int*>(ia),
  48. input_iterator<const int*>(ia + sa),
  49. forward_iterator<const int*>(ic),
  50. forward_iterator<const int*>(ic + 1)) ==
  51. input_iterator<const int*>(ia+sa));
  52. assert(std::find_first_of(input_iterator<const int*>(ia),
  53. input_iterator<const int*>(ia + sa),
  54. forward_iterator<const int*>(ic),
  55. forward_iterator<const int*>(ic)) ==
  56. input_iterator<const int*>(ia+sa));
  57. assert(std::find_first_of(input_iterator<const int*>(ia),
  58. input_iterator<const int*>(ia),
  59. forward_iterator<const int*>(ic),
  60. forward_iterator<const int*>(ic+1)) ==
  61. input_iterator<const int*>(ia));
  62. #if TEST_STD_VER > 17
  63. static_assert(test_constexpr());
  64. #endif
  65. }