diff --git a/include/experimental/algorithm b/include/experimental/algorithm index a2e956f2..ffaa793b 100644 --- a/include/experimental/algorithm +++ b/include/experimental/algorithm @@ -50,6 +50,12 @@ SampleIterator sample(PopulationIterator first, PopulationIterator last, _LIBCPP_BEGIN_NAMESPACE_LFTS +template +_LIBCPP_INLINE_VISIBILITY +_ForwardIterator search(_ForwardIterator __f, _ForwardIterator __l, const _Searcher &__s) +{ return __s(__f, __l); } + + template _LIBCPP_INLINE_VISIBILITY diff --git a/test/std/experimental/algorithms/alg.search/search.pass.cpp b/test/std/experimental/algorithms/alg.search/search.pass.cpp new file mode 100644 index 00000000..e27f0e43 --- /dev/null +++ b/test/std/experimental/algorithms/alg.search/search.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// ForwardIterator search(ForwardIterator first, ForwardIterator last, +// const Searcher& searcher); +// +// returns searcher.operator(first, last) +// + +#include +#include + +#include "test_iterators.h" + +int searcher_called = 0; + +struct MySearcher { + template + Iterator operator() ( Iterator b, Iterator /*e*/) const + { + ++searcher_called; + return b; + } +}; + + +int main() { + typedef int * RI; + static_assert(std::is_same::value, "" ); + + RI it{nullptr}; + assert(it == std::experimental::search(it, it, MySearcher())); + assert(searcher_called == 1); +}