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 // <algorithm> 11 12 // template<InputIterator Iter, Predicate<auto, Iter::value_type> Pred> 13 // requires CopyConstructible<Pred> 14 // constexpr Iter // constexpr after C++17 15 // find_if(Iter first, Iter last, Pred pred); 16 17 #include <algorithm> 18 #include <functional> 19 #include <cassert> 20 21 #include "test_macros.h" 22 #include "test_iterators.h" 23 24 struct eq { 25 TEST_CONSTEXPR eq (int val) : v(val) {} 26 TEST_CONSTEXPR bool operator () (int v2) const { return v == v2; } 27 int v; 28 }; 29 30 #if TEST_STD_VER > 17 31 TEST_CONSTEXPR bool test_constexpr() { 32 int ia[] = {1, 3, 5, 2, 4, 6}; 33 int ib[] = {1, 2, 3, 7, 5, 6}; 34 eq c(4); 35 return (std::find_if(std::begin(ia), std::end(ia), c) == ia+4) 36 && (std::find_if(std::begin(ib), std::end(ib), c) == ib+6) 37 ; 38 } 39 #endif 40 41 int main() 42 { 43 int ia[] = {0, 1, 2, 3, 4, 5}; 44 const unsigned s = sizeof(ia)/sizeof(ia[0]); 45 input_iterator<const int*> r = std::find_if(input_iterator<const int*>(ia), 46 input_iterator<const int*>(ia+s), 47 eq(3)); 48 assert(*r == 3); 49 r = std::find_if(input_iterator<const int*>(ia), 50 input_iterator<const int*>(ia+s), 51 eq(10)); 52 assert(r == input_iterator<const int*>(ia+s)); 53 54 #if TEST_STD_VER > 17 55 static_assert(test_constexpr()); 56 #endif 57 } 58