diff options
author | Marshall Clow <mclow.lists@gmail.com> | 2015-07-20 15:40:27 +0000 |
---|---|---|
committer | Marshall Clow <mclow.lists@gmail.com> | 2015-07-20 15:40:27 +0000 |
commit | 81416e492e738c5c4da3f387f0c337f113d965c7 (patch) | |
tree | ed6f9664e62b1bdb080930cae7049908542de8bd | |
parent | b5960564133b8794fc1065869b9e2d4fbf6530ea (diff) | |
download | bcm5719-llvm-81416e492e738c5c4da3f387f0c337f113d965c7.tar.gz bcm5719-llvm-81416e492e738c5c4da3f387f0c337f113d965c7.zip |
Implement the plugin-based version of std::search. There are no searchers yet; those are coming soon.
llvm-svn: 242679
-rw-r--r-- | libcxx/include/experimental/algorithm | 6 | ||||
-rw-r--r-- | libcxx/test/std/experimental/algorithms/alg.search/search.pass.cpp | 43 |
2 files changed, 49 insertions, 0 deletions
diff --git a/libcxx/include/experimental/algorithm b/libcxx/include/experimental/algorithm index a2e956f281a..ffaa793b6d4 100644 --- a/libcxx/include/experimental/algorithm +++ b/libcxx/include/experimental/algorithm @@ -50,6 +50,12 @@ SampleIterator sample(PopulationIterator first, PopulationIterator last, _LIBCPP_BEGIN_NAMESPACE_LFTS +template <class _ForwardIterator, class _Searcher> +_LIBCPP_INLINE_VISIBILITY +_ForwardIterator search(_ForwardIterator __f, _ForwardIterator __l, const _Searcher &__s) +{ return __s(__f, __l); } + + template <class _PopulationIterator, class _SampleIterator, class _Distance, class _UniformRandomNumberGenerator> _LIBCPP_INLINE_VISIBILITY diff --git a/libcxx/test/std/experimental/algorithms/alg.search/search.pass.cpp b/libcxx/test/std/experimental/algorithms/alg.search/search.pass.cpp new file mode 100644 index 00000000000..e27f0e43b18 --- /dev/null +++ b/libcxx/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. +// +//===----------------------------------------------------------------------===// + +// <algorithm> + +// template<class ForwardIterator, class Searcher> +// ForwardIterator search(ForwardIterator first, ForwardIterator last, +// const Searcher& searcher); +// +// returns searcher.operator(first, last) +// + +#include <experimental/algorithm> +#include <cassert> + +#include "test_iterators.h" + +int searcher_called = 0; + +struct MySearcher { + template <typename Iterator> + Iterator operator() ( Iterator b, Iterator /*e*/) const + { + ++searcher_called; + return b; + } +}; + + +int main() { + typedef int * RI; + static_assert(std::is_same<RI, decltype(std::experimental::search(RI(), RI(), MySearcher()))>::value, "" ); + + RI it{nullptr}; + assert(it == std::experimental::search(it, it, MySearcher())); + assert(searcher_called == 1); +} |