[libcxx] r242682 - Implement the default searcher for std::experimental::search.

Marshall Clow mclow.lists at gmail.com
Mon Jul 20 09:39:28 PDT 2015


Author: marshall
Date: Mon Jul 20 11:39:28 2015
New Revision: 242682

URL: http://llvm.org/viewvc/llvm-project?rev=242682&view=rev
Log:
Implement the default searcher for std::experimental::search.

Added:
    libcxx/trunk/include/experimental/functional
    libcxx/trunk/test/std/experimental/func/
    libcxx/trunk/test/std/experimental/func/func.searchers/
    libcxx/trunk/test/std/experimental/func/func.searchers/func.searchers.default/
    libcxx/trunk/test/std/experimental/func/func.searchers/func.searchers.default/default.pass.cpp
    libcxx/trunk/test/std/experimental/func/func.searchers/func.searchers.default/default.pred.pass.cpp
    libcxx/trunk/test/std/experimental/func/func.searchers/func.searchers.default/func.searchers.default.creation/
    libcxx/trunk/test/std/experimental/func/func.searchers/func.searchers.default/func.searchers.default.creation/make_default_searcher.pass.cpp
    libcxx/trunk/test/std/experimental/func/func.searchers/func.searchers.default/func.searchers.default.creation/make_default_searcher.pred.pass.cpp
    libcxx/trunk/test/std/experimental/func/func.searchers/nothing_to_do.pass.cpp
    libcxx/trunk/test/std/experimental/func/header.functional.synop/
    libcxx/trunk/test/std/experimental/func/header.functional.synop/includes.pass.cpp
    libcxx/trunk/test/std/experimental/func/nothing_to_do.pass.cpp

Added: libcxx/trunk/include/experimental/functional
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/experimental/functional?rev=242682&view=auto
==============================================================================
--- libcxx/trunk/include/experimental/functional (added)
+++ libcxx/trunk/include/experimental/functional Mon Jul 20 11:39:28 2015
@@ -0,0 +1,133 @@
+// -*- C++ -*-
+//===-------------------------- functional --------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_EXPERIMENTAL_FUNCTIONAL
+#define _LIBCPP_EXPERIMENTAL_FUNCTIONAL
+
+/*
+   experimental/functional synopsis
+
+#include <algorithm>
+
+namespace std {
+namespace experimental {
+inline namespace fundamentals_v1 {
+
+    // See C++14 §20.9.9, Function object binders
+    template <class T> constexpr bool is_bind_expression_v
+      = is_bind_expression<T>::value;
+    template <class T> constexpr int is_placeholder_v
+      = is_placeholder<T>::value;
+
+    // 4.2, Class template function
+    template<class> class function; // undefined
+    template<class R, class... ArgTypes> class function<R(ArgTypes...)>;
+
+    template<class R, class... ArgTypes>
+    void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&);
+
+    template<class R, class... ArgTypes>
+    bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
+    template<class R, class... ArgTypes>
+    bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
+    template<class R, class... ArgTypes>
+    bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
+    template<class R, class... ArgTypes>
+    bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
+
+    // 4.3, Searchers
+    template<class ForwardIterator, class BinaryPredicate = equal_to<>>
+      class default_searcher;
+
+    template<class RandomAccessIterator,
+             class Hash = hash<typename iterator_traits<RandomAccessIterator>::value_type>,
+             class BinaryPredicate = equal_to<>>
+      class boyer_moore_searcher;
+
+    template<class RandomAccessIterator,
+             class Hash = hash<typename iterator_traits<RandomAccessIterator>::value_type>,
+             class BinaryPredicate = equal_to<>>
+      class boyer_moore_horspool_searcher;
+
+    template<class ForwardIterator, class BinaryPredicate = equal_to<>>
+    default_searcher<ForwardIterator, BinaryPredicate>
+    make_default_searcher(ForwardIterator pat_first, ForwardIterator pat_last,
+                          BinaryPredicate pred = BinaryPredicate());
+
+    template<class RandomAccessIterator,
+             class Hash = hash<typename iterator_traits<RandomAccessIterator>::value_type>,
+             class BinaryPredicate = equal_to<>>
+    boyer_moore_searcher<RandomAccessIterator, Hash, BinaryPredicate>
+    make_boyer_moore_searcher(
+        RandomAccessIterator pat_first, RandomAccessIterator pat_last,
+        Hash hf = Hash(), BinaryPredicate pred = BinaryPredicate());
+
+    template<class RandomAccessIterator,
+             class Hash = hash<typename iterator_traits<RandomAccessIterator>::value_type>,
+             class BinaryPredicate = equal_to<>>
+    boyer_moore_horspool_searcher<RandomAccessIterator, Hash, BinaryPredicate>
+    make_boyer_moore_horspool_searcher(
+        RandomAccessIterator pat_first, RandomAccessIterator pat_last,
+        Hash hf = Hash(), BinaryPredicate pred = BinaryPredicate());
+
+  } // namespace fundamentals_v1
+  } // namespace experimental
+
+  template<class R, class... ArgTypes, class Alloc>
+  struct uses_allocator<experimental::function<R(ArgTypes...)>, Alloc>;
+
+} // namespace std
+
+*/
+
+#include <experimental/__config>
+#include <functional>
+#include <algorithm>
+
+#include <__undef_min_max>
+
+#include <__debug>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_LFTS
+
+// default searcher
+template<class _ForwardIterator, class _BinaryPredicate = equal_to<>>
+class default_searcher {
+public:
+    default_searcher(_ForwardIterator __f, _ForwardIterator __l, 
+                       _BinaryPredicate __p = _BinaryPredicate())
+        : __first_(__f), __last_(__l), __pred_(__p) {}
+
+    template <typename _ForwardIterator2>
+    _ForwardIterator2 operator () (_ForwardIterator2 __f, _ForwardIterator2 __l) const {
+        return _VSTD::search(__f, __l, __first_, __last_, __pred_);
+        }
+
+private:
+    _ForwardIterator __first_;
+    _ForwardIterator __last_;
+    _BinaryPredicate __pred_;
+    };
+
+template<class _ForwardIterator, class _BinaryPredicate = equal_to<>>
+default_searcher<_ForwardIterator, _BinaryPredicate>
+make_default_searcher( _ForwardIterator __f, _ForwardIterator __l, _BinaryPredicate __p = _BinaryPredicate ())
+{
+    return default_searcher<_ForwardIterator, _BinaryPredicate>(__f, __l, __p);
+}
+
+
+_LIBCPP_END_NAMESPACE_LFTS
+
+#endif /* _LIBCPP_EXPERIMENTAL_FUNCTIONAL */

Added: libcxx/trunk/test/std/experimental/func/func.searchers/func.searchers.default/default.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/func/func.searchers/func.searchers.default/default.pass.cpp?rev=242682&view=auto
==============================================================================
--- libcxx/trunk/test/std/experimental/func/func.searchers/func.searchers.default/default.pass.cpp (added)
+++ libcxx/trunk/test/std/experimental/func/func.searchers/func.searchers.default/default.pass.cpp Mon Jul 20 11:39:28 2015
@@ -0,0 +1,93 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <functional>
+
+// default searcher
+// template<class _ForwardIterator, class _BinaryPredicate = equal_to<>>
+// class default_searcher {
+// public:
+//     default_searcher(_ForwardIterator __f, _ForwardIterator __l, 
+//                             _BinaryPredicate __p = _BinaryPredicate())
+//         : __first_(__f), __last_(__l), __pred_(__p) {}
+// 
+//     template <typename _ForwardIterator2>
+//     _ForwardIterator2 operator () (_ForwardIterator2 __f, _ForwardIterator2 __l) const {
+//         return std::search(__f, __l, __first_, __last_, __pred_);
+//         }
+// 
+// private:
+//     _ForwardIterator __first_;
+//     _ForwardIterator __last_;
+//     _BinaryPredicate __pred_;
+//     };
+
+
+#include <experimental/algorithm>
+#include <experimental/functional>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <typename Iter1, typename Iter2>
+void do_search(Iter1 b1, Iter1 e1, Iter2 b2, Iter2 e2, Iter1 result) {
+    std::experimental::default_searcher<Iter2> s{b2, e2};
+    assert(result == std::experimental::search(b1, e1, s));
+}
+
+template <class Iter1, class Iter2>
+void
+test()
+{
+    int ia[] = {0, 1, 2, 3, 4, 5};
+    const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+    do_search(Iter1(ia), Iter1(ia+sa),   Iter2(ia),      Iter2(ia),    Iter1(ia));
+    do_search(Iter1(ia), Iter1(ia+sa),   Iter2(ia),      Iter2(ia+1),  Iter1(ia));
+    do_search(Iter1(ia), Iter1(ia+sa),   Iter2(ia+1),    Iter2(ia+2),  Iter1(ia+1));
+    do_search(Iter1(ia), Iter1(ia+sa),   Iter2(ia+2),    Iter2(ia+2),  Iter1(ia));
+    do_search(Iter1(ia), Iter1(ia+sa),   Iter2(ia+2),    Iter2(ia+3),  Iter1(ia+2));
+    do_search(Iter1(ia), Iter1(ia+sa),   Iter2(ia+2),    Iter2(ia+3),  Iter1(ia+2));
+    do_search(Iter1(ia), Iter1(ia),      Iter2(ia+2),    Iter2(ia+3),  Iter1(ia));
+    do_search(Iter1(ia), Iter1(ia+sa),   Iter2(ia+sa-1), Iter2(ia+sa), Iter1(ia+sa-1));
+    do_search(Iter1(ia), Iter1(ia+sa),   Iter2(ia+sa-3), Iter2(ia+sa), Iter1(ia+sa-3));
+    do_search(Iter1(ia), Iter1(ia+sa),   Iter2(ia),      Iter2(ia+sa), Iter1(ia));
+    do_search(Iter1(ia), Iter1(ia+sa-1), Iter2(ia),      Iter2(ia+sa), Iter1(ia+sa-1));
+    do_search(Iter1(ia), Iter1(ia+1),    Iter2(ia),      Iter2(ia+sa), Iter1(ia+1));
+    int ib[] = {0, 1, 2, 0, 1, 2, 3, 0, 1, 2, 3, 4};
+    const unsigned sb = sizeof(ib)/sizeof(ib[0]);
+    int ic[] = {1};
+    do_search(Iter1(ib), Iter1(ib+sb), Iter2(ic), Iter2(ic+1), Iter1(ib+1));
+    int id[] = {1, 2};
+    do_search(Iter1(ib), Iter1(ib+sb), Iter2(id), Iter2(id+2), Iter1(ib+1));
+    int ie[] = {1, 2, 3};
+    do_search(Iter1(ib), Iter1(ib+sb), Iter2(ie), Iter2(ie+3), Iter1(ib+4));
+    int ig[] = {1, 2, 3, 4};
+    do_search(Iter1(ib), Iter1(ib+sb), Iter2(ig), Iter2(ig+4), Iter1(ib+8));
+    int ih[] = {0, 1, 1, 1, 1, 2, 3, 0, 1, 2, 3, 4};
+    const unsigned sh = sizeof(ih)/sizeof(ih[0]);
+    int ii[] = {1, 1, 2};
+    do_search(Iter1(ih), Iter1(ih+sh), Iter2(ii), Iter2(ii+3), Iter1(ih+3));
+    int ij[] = {0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0};
+    const unsigned sj = sizeof(ij)/sizeof(ij[0]);
+    int ik[] = {0, 0, 0, 0, 1, 1, 1, 1, 0, 0};
+    const unsigned sk = sizeof(ik)/sizeof(ik[0]);
+    do_search(Iter1(ij), Iter1(ij+sj), Iter2(ik), Iter2(ik+sk), Iter1(ij+6));
+}
+
+int main() {
+    test<forward_iterator<const int*>, forward_iterator<const int*> >();
+    test<forward_iterator<const int*>, bidirectional_iterator<const int*> >();
+    test<forward_iterator<const int*>, random_access_iterator<const int*> >();
+    test<bidirectional_iterator<const int*>, forward_iterator<const int*> >();
+    test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*> >();
+    test<bidirectional_iterator<const int*>, random_access_iterator<const int*> >();
+    test<random_access_iterator<const int*>, forward_iterator<const int*> >();
+    test<random_access_iterator<const int*>, bidirectional_iterator<const int*> >();
+    test<random_access_iterator<const int*>, random_access_iterator<const int*> >();
+}

Added: libcxx/trunk/test/std/experimental/func/func.searchers/func.searchers.default/default.pred.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/func/func.searchers/func.searchers.default/default.pred.pass.cpp?rev=242682&view=auto
==============================================================================
--- libcxx/trunk/test/std/experimental/func/func.searchers/func.searchers.default/default.pred.pass.cpp (added)
+++ libcxx/trunk/test/std/experimental/func/func.searchers/func.searchers.default/default.pred.pass.cpp Mon Jul 20 11:39:28 2015
@@ -0,0 +1,100 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <functional>
+
+// default searcher
+// template<class _ForwardIterator, class _BinaryPredicate = equal_to<>>
+// class default_searcher {
+// public:
+//     default_searcher(_ForwardIterator __f, _ForwardIterator __l, 
+//                             _BinaryPredicate __p = _BinaryPredicate())
+//         : __first_(__f), __last_(__l), __pred_(__p) {}
+// 
+//     template <typename _ForwardIterator2>
+//     _ForwardIterator2 operator () (_ForwardIterator2 __f, _ForwardIterator2 __l) const {
+//         return std::search(__f, __l, __first_, __last_, __pred_);
+//         }
+// 
+// private:
+//     _ForwardIterator __first_;
+//     _ForwardIterator __last_;
+//     _BinaryPredicate __pred_;
+//     };
+
+
+#include <experimental/algorithm>
+#include <experimental/functional>
+#include <cassert>
+
+#include "test_iterators.h"
+
+struct count_equal
+{
+    static unsigned count;
+    template <class T>
+    bool operator()(const T& x, const T& y)
+        {++count; return x == y;}
+};
+
+unsigned count_equal::count = 0;
+
+template <typename Iter1, typename Iter2>
+void do_search(Iter1 b1, Iter1 e1, Iter2 b2, Iter2 e2, Iter1 result, unsigned max_count) {
+    std::experimental::default_searcher<Iter2, count_equal> s{b2, e2};
+    count_equal::count = 0;
+    assert(result == std::experimental::search(b1, e1, s));
+    assert(count_equal::count <= max_count);
+}
+
+template <class Iter1, class Iter2>
+void
+test()
+{
+    int ia[] = {0, 1, 2, 3, 4, 5};
+    const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+    do_search(Iter1(ia), Iter1(ia+sa),   Iter2(ia),      Iter2(ia),    Iter1(ia),      0);
+    do_search(Iter1(ia), Iter1(ia+sa),   Iter2(ia),      Iter2(ia+1),  Iter1(ia),      sa);
+    do_search(Iter1(ia), Iter1(ia+sa),   Iter2(ia+1),    Iter2(ia+2),  Iter1(ia+1),    sa);
+    do_search(Iter1(ia), Iter1(ia+sa),   Iter2(ia+2),    Iter2(ia+2),  Iter1(ia),      0);
+    do_search(Iter1(ia), Iter1(ia+sa),   Iter2(ia+2),    Iter2(ia+3),  Iter1(ia+2),    sa);
+    do_search(Iter1(ia), Iter1(ia+sa),   Iter2(ia+2),    Iter2(ia+3),  Iter1(ia+2),    sa);
+    do_search(Iter1(ia), Iter1(ia),      Iter2(ia+2),    Iter2(ia+3),  Iter1(ia),      0);
+    do_search(Iter1(ia), Iter1(ia+sa),   Iter2(ia+sa-1), Iter2(ia+sa), Iter1(ia+sa-1), sa);
+    do_search(Iter1(ia), Iter1(ia+sa),   Iter2(ia+sa-3), Iter2(ia+sa), Iter1(ia+sa-3), 3*sa);
+    do_search(Iter1(ia), Iter1(ia+sa),   Iter2(ia),      Iter2(ia+sa), Iter1(ia),      sa*sa);
+    do_search(Iter1(ia), Iter1(ia+sa-1), Iter2(ia),      Iter2(ia+sa), Iter1(ia+sa-1), (sa-1)*sa);
+    do_search(Iter1(ia), Iter1(ia+1),    Iter2(ia),      Iter2(ia+sa), Iter1(ia+1),    sa);
+    int ib[] = {0, 1, 2, 0, 1, 2, 3, 0, 1, 2, 3, 4};
+    const unsigned sb = sizeof(ib)/sizeof(ib[0]);
+    int ic[] = {1};
+    do_search(Iter1(ib), Iter1(ib+sb), Iter2(ic), Iter2(ic+1), Iter1(ib+1), sb);
+    int id[] = {1, 2};
+    do_search(Iter1(ib), Iter1(ib+sb), Iter2(id), Iter2(id+2), Iter1(ib+1), sb*2);
+    int ie[] = {1, 2, 3};
+    do_search(Iter1(ib), Iter1(ib+sb), Iter2(ie), Iter2(ie+3), Iter1(ib+4), sb*3);
+    int ig[] = {1, 2, 3, 4};
+    do_search(Iter1(ib), Iter1(ib+sb), Iter2(ig), Iter2(ig+4), Iter1(ib+8), sb*4);
+    int ih[] = {0, 1, 1, 1, 1, 2, 3, 0, 1, 2, 3, 4};
+    const unsigned sh = sizeof(ih)/sizeof(ih[0]);
+    int ii[] = {1, 1, 2};
+    do_search(Iter1(ih), Iter1(ih+sh), Iter2(ii), Iter2(ii+3), Iter1(ih+3),  sh*3);
+}
+
+int main() {
+    test<forward_iterator<const int*>, forward_iterator<const int*> >();
+    test<forward_iterator<const int*>, bidirectional_iterator<const int*> >();
+    test<forward_iterator<const int*>, random_access_iterator<const int*> >();
+    test<bidirectional_iterator<const int*>, forward_iterator<const int*> >();
+    test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*> >();
+    test<bidirectional_iterator<const int*>, random_access_iterator<const int*> >();
+    test<random_access_iterator<const int*>, forward_iterator<const int*> >();
+    test<random_access_iterator<const int*>, bidirectional_iterator<const int*> >();
+    test<random_access_iterator<const int*>, random_access_iterator<const int*> >();
+}

Added: libcxx/trunk/test/std/experimental/func/func.searchers/func.searchers.default/func.searchers.default.creation/make_default_searcher.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/func/func.searchers/func.searchers.default/func.searchers.default.creation/make_default_searcher.pass.cpp?rev=242682&view=auto
==============================================================================
--- libcxx/trunk/test/std/experimental/func/func.searchers/func.searchers.default/func.searchers.default.creation/make_default_searcher.pass.cpp (added)
+++ libcxx/trunk/test/std/experimental/func/func.searchers/func.searchers.default/func.searchers.default.creation/make_default_searcher.pass.cpp Mon Jul 20 11:39:28 2015
@@ -0,0 +1,79 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <functional>
+
+// template<class ForwardIterator, class BinaryPredicate = equal_to<>>
+// default_searcher<ForwardIterator, BinaryPredicate>
+// make_default_searcher(ForwardIterator pat_first, ForwardIterator pat_last,
+//                       BinaryPredicate pred = BinaryPredicate());
+
+
+#include <experimental/algorithm>
+#include <experimental/functional>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <typename Iter1, typename Iter2>
+void do_search(Iter1 b1, Iter1 e1, Iter2 b2, Iter2 e2, Iter1 result) {
+    assert(result == std::experimental::search(b1, e1, 
+        std::experimental::make_default_searcher(b2, e2)));
+}
+
+template <class Iter1, class Iter2>
+void
+test()
+{
+    int ia[] = {0, 1, 2, 3, 4, 5};
+    const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+    do_search(Iter1(ia), Iter1(ia+sa),   Iter2(ia),      Iter2(ia),     Iter1(ia));
+    do_search(Iter1(ia), Iter1(ia+sa),   Iter2(ia),      Iter2(ia+1),  Iter1(ia));
+    do_search(Iter1(ia), Iter1(ia+sa),   Iter2(ia+1),    Iter2(ia+2),  Iter1(ia+1));
+    do_search(Iter1(ia), Iter1(ia+sa),   Iter2(ia+2),    Iter2(ia+2),  Iter1(ia));
+    do_search(Iter1(ia), Iter1(ia+sa),   Iter2(ia+2),    Iter2(ia+3),  Iter1(ia+2));
+    do_search(Iter1(ia), Iter1(ia+sa),   Iter2(ia+2),    Iter2(ia+3),  Iter1(ia+2));
+    do_search(Iter1(ia), Iter1(ia),      Iter2(ia+2),    Iter2(ia+3),  Iter1(ia));
+    do_search(Iter1(ia), Iter1(ia+sa),   Iter2(ia+sa-1), Iter2(ia+sa), Iter1(ia+sa-1));
+    do_search(Iter1(ia), Iter1(ia+sa),   Iter2(ia+sa-3), Iter2(ia+sa), Iter1(ia+sa-3));
+    do_search(Iter1(ia), Iter1(ia+sa),   Iter2(ia),      Iter2(ia+sa), Iter1(ia));
+    do_search(Iter1(ia), Iter1(ia+sa-1), Iter2(ia),      Iter2(ia+sa), Iter1(ia+sa-1));
+    do_search(Iter1(ia), Iter1(ia+1),    Iter2(ia),      Iter2(ia+sa), Iter1(ia+1));
+    int ib[] = {0, 1, 2, 0, 1, 2, 3, 0, 1, 2, 3, 4};
+    const unsigned sb = sizeof(ib)/sizeof(ib[0]);
+    int ic[] = {1};
+    do_search(Iter1(ib), Iter1(ib+sb), Iter2(ic), Iter2(ic+1), Iter1(ib+1));
+    int id[] = {1, 2};
+    do_search(Iter1(ib), Iter1(ib+sb), Iter2(id), Iter2(id+2), Iter1(ib+1));
+    int ie[] = {1, 2, 3};
+    do_search(Iter1(ib), Iter1(ib+sb), Iter2(ie), Iter2(ie+3), Iter1(ib+4));
+    int ig[] = {1, 2, 3, 4};
+    do_search(Iter1(ib), Iter1(ib+sb), Iter2(ig), Iter2(ig+4), Iter1(ib+8));
+    int ih[] = {0, 1, 1, 1, 1, 2, 3, 0, 1, 2, 3, 4};
+    const unsigned sh = sizeof(ih)/sizeof(ih[0]);
+    int ii[] = {1, 1, 2};
+    do_search(Iter1(ih), Iter1(ih+sh), Iter2(ii), Iter2(ii+3), Iter1(ih+3));
+    int ij[] = {0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0};
+    const unsigned sj = sizeof(ij)/sizeof(ij[0]);
+    int ik[] = {0, 0, 0, 0, 1, 1, 1, 1, 0, 0};
+    const unsigned sk = sizeof(ik)/sizeof(ik[0]);
+    do_search(Iter1(ij), Iter1(ij+sj), Iter2(ik), Iter2(ik+sk), Iter1(ij+6));
+}
+
+int main() {
+    test<forward_iterator<const int*>, forward_iterator<const int*> >();
+    test<forward_iterator<const int*>, bidirectional_iterator<const int*> >();
+    test<forward_iterator<const int*>, random_access_iterator<const int*> >();
+    test<bidirectional_iterator<const int*>, forward_iterator<const int*> >();
+    test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*> >();
+    test<bidirectional_iterator<const int*>, random_access_iterator<const int*> >();
+    test<random_access_iterator<const int*>, forward_iterator<const int*> >();
+    test<random_access_iterator<const int*>, bidirectional_iterator<const int*> >();
+    test<random_access_iterator<const int*>, random_access_iterator<const int*> >();
+}

Added: libcxx/trunk/test/std/experimental/func/func.searchers/func.searchers.default/func.searchers.default.creation/make_default_searcher.pred.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/func/func.searchers/func.searchers.default/func.searchers.default.creation/make_default_searcher.pred.pass.cpp?rev=242682&view=auto
==============================================================================
--- libcxx/trunk/test/std/experimental/func/func.searchers/func.searchers.default/func.searchers.default.creation/make_default_searcher.pred.pass.cpp (added)
+++ libcxx/trunk/test/std/experimental/func/func.searchers/func.searchers.default/func.searchers.default.creation/make_default_searcher.pred.pass.cpp Mon Jul 20 11:39:28 2015
@@ -0,0 +1,86 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <functional>
+
+// template<class ForwardIterator, class BinaryPredicate = equal_to<>>
+// default_searcher<ForwardIterator, BinaryPredicate>
+// make_default_searcher(ForwardIterator pat_first, ForwardIterator pat_last,
+//                       BinaryPredicate pred = BinaryPredicate());
+
+
+#include <experimental/algorithm>
+#include <experimental/functional>
+#include <cassert>
+
+#include "test_iterators.h"
+
+struct count_equal
+{
+    static unsigned count;
+    template <class T>
+    bool operator()(const T& x, const T& y)
+        {++count; return x == y;}
+};
+
+unsigned count_equal::count = 0;
+
+template <typename Iter1, typename Iter2>
+void do_search(Iter1 b1, Iter1 e1, Iter2 b2, Iter2 e2, Iter1 result, unsigned max_count) {
+    count_equal::count = 0;
+    assert(result == std::experimental::search(b1, e1, 
+        std::experimental::make_default_searcher(b2, e2)));
+    assert(count_equal::count <= max_count);
+}
+
+template <class Iter1, class Iter2>
+void
+test()
+{
+    int ia[] = {0, 1, 2, 3, 4, 5};
+    const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+    do_search(Iter1(ia), Iter1(ia+sa),   Iter2(ia),      Iter2(ia),    Iter1(ia),      0);
+    do_search(Iter1(ia), Iter1(ia+sa),   Iter2(ia),      Iter2(ia+1),  Iter1(ia),      sa);
+    do_search(Iter1(ia), Iter1(ia+sa),   Iter2(ia+1),    Iter2(ia+2),  Iter1(ia+1),    sa);
+    do_search(Iter1(ia), Iter1(ia+sa),   Iter2(ia+2),    Iter2(ia+2),  Iter1(ia),      0);
+    do_search(Iter1(ia), Iter1(ia+sa),   Iter2(ia+2),    Iter2(ia+3),  Iter1(ia+2),    sa);
+    do_search(Iter1(ia), Iter1(ia+sa),   Iter2(ia+2),    Iter2(ia+3),  Iter1(ia+2),    sa);
+    do_search(Iter1(ia), Iter1(ia),      Iter2(ia+2),    Iter2(ia+3),  Iter1(ia),      0);
+    do_search(Iter1(ia), Iter1(ia+sa),   Iter2(ia+sa-1), Iter2(ia+sa), Iter1(ia+sa-1), sa);
+    do_search(Iter1(ia), Iter1(ia+sa),   Iter2(ia+sa-3), Iter2(ia+sa), Iter1(ia+sa-3), 3*sa);
+    do_search(Iter1(ia), Iter1(ia+sa),   Iter2(ia),      Iter2(ia+sa), Iter1(ia),      sa*sa);
+    do_search(Iter1(ia), Iter1(ia+sa-1), Iter2(ia),      Iter2(ia+sa), Iter1(ia+sa-1), (sa-1)*sa);
+    do_search(Iter1(ia), Iter1(ia+1),    Iter2(ia),      Iter2(ia+sa), Iter1(ia+1),    sa);
+    int ib[] = {0, 1, 2, 0, 1, 2, 3, 0, 1, 2, 3, 4};
+    const unsigned sb = sizeof(ib)/sizeof(ib[0]);
+    int ic[] = {1};
+    do_search(Iter1(ib), Iter1(ib+sb), Iter2(ic), Iter2(ic+1), Iter1(ib+1), sb);
+    int id[] = {1, 2};
+    do_search(Iter1(ib), Iter1(ib+sb), Iter2(id), Iter2(id+2), Iter1(ib+1), sb*2);
+    int ie[] = {1, 2, 3};
+    do_search(Iter1(ib), Iter1(ib+sb), Iter2(ie), Iter2(ie+3), Iter1(ib+4), sb*3);
+    int ig[] = {1, 2, 3, 4};
+    do_search(Iter1(ib), Iter1(ib+sb), Iter2(ig), Iter2(ig+4), Iter1(ib+8), sb*4);
+    int ih[] = {0, 1, 1, 1, 1, 2, 3, 0, 1, 2, 3, 4};
+    const unsigned sh = sizeof(ih)/sizeof(ih[0]);
+    int ii[] = {1, 1, 2};
+    do_search(Iter1(ih), Iter1(ih+sh), Iter2(ii), Iter2(ii+3), Iter1(ih+3),  sh*3);
+}
+
+int main() {
+    test<forward_iterator<const int*>, forward_iterator<const int*> >();
+    test<forward_iterator<const int*>, bidirectional_iterator<const int*> >();
+    test<forward_iterator<const int*>, random_access_iterator<const int*> >();
+    test<bidirectional_iterator<const int*>, forward_iterator<const int*> >();
+    test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*> >();
+    test<bidirectional_iterator<const int*>, random_access_iterator<const int*> >();
+    test<random_access_iterator<const int*>, forward_iterator<const int*> >();
+    test<random_access_iterator<const int*>, bidirectional_iterator<const int*> >();
+    test<random_access_iterator<const int*>, random_access_iterator<const int*> >();
+}

Added: libcxx/trunk/test/std/experimental/func/func.searchers/nothing_to_do.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/func/func.searchers/nothing_to_do.pass.cpp?rev=242682&view=auto
==============================================================================
--- libcxx/trunk/test/std/experimental/func/func.searchers/nothing_to_do.pass.cpp (added)
+++ libcxx/trunk/test/std/experimental/func/func.searchers/nothing_to_do.pass.cpp Mon Jul 20 11:39:28 2015
@@ -0,0 +1,13 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+int main()
+{
+}

Added: libcxx/trunk/test/std/experimental/func/header.functional.synop/includes.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/func/header.functional.synop/includes.pass.cpp?rev=242682&view=auto
==============================================================================
--- libcxx/trunk/test/std/experimental/func/header.functional.synop/includes.pass.cpp (added)
+++ libcxx/trunk/test/std/experimental/func/header.functional.synop/includes.pass.cpp Mon Jul 20 11:39:28 2015
@@ -0,0 +1,21 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03, c++11
+
+// <experimental/functional>
+//
+//  has to include <functional>
+
+#include <experimental/functional>
+
+int main()
+{
+  std::function<int(int)> x;
+}

Added: libcxx/trunk/test/std/experimental/func/nothing_to_do.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/func/nothing_to_do.pass.cpp?rev=242682&view=auto
==============================================================================
--- libcxx/trunk/test/std/experimental/func/nothing_to_do.pass.cpp (added)
+++ libcxx/trunk/test/std/experimental/func/nothing_to_do.pass.cpp Mon Jul 20 11:39:28 2015
@@ -0,0 +1,13 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+int main()
+{
+}






More information about the cfe-commits mailing list