+2008-06-26 Paolo Carlini <paolo.carlini@oracle.com>
+
+ * include/bits/stl_algo.h (partition_copy): Add in C++0x mode.
+ * include/bits/algorithmfwd.h: Add.
+ * testsuite/25_algorithms/headers/algorithm/synopsis.cc: Update.
+ * testsuite/25_algorithms/partition_copy/1.cc: New.
+ * testsuite/25_algorithms/partition_copy/check_type.cc: Likewise.
+ * testsuite/25_algorithms/partition_copy/requirements/
+ explicit_instantiation/2.cc: Likewise.
+ * testsuite/25_algorithms/partition_copy/requirements/
+ explicit_instantiation/pod.cc: Likewise.
+
2008-06-26 Chris Fairles <chris.fairles@gmail.com>
* testsuite/20_util/unique_ptr/cons/pointer_array.cc: New.
/*
adjacent_find
+ all_of (C++0x)
+ any_of (C++0x)
binary_search
copy
copy_backward
+ copy_if (C++0x)
count
count_if
equal
find_end
find_first_of
find_if
+ find_if_not (C++0x)
for_each
generate
generate_n
minmax_element (C++0x)
mismatch
next_permutation
+ none_of (C++0x)
nth_element
partial_sort
partial_sort_copy
partition
+ partition_copy (C++0x)
pop_heap
prev_permutation
push_heap
// adjacent_find
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ template<typename _IIter, typename _Predicate>
+ bool
+ all_of(_IIter, _IIter, _Predicate);
+
+ template<typename _IIter, typename _Predicate>
+ bool
+ any_of(_IIter, _IIter, _Predicate);
+#endif
+
template<typename _FIter, typename _Tp>
bool
binary_search(_FIter, _FIter, const _Tp&);
_BIter2
copy_backward(_BIter1, _BIter1, _BIter2);
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ template<typename _IIter, typename _OIter, typename _Predicate>
+ _OIter
+ copy_if(_IIter, _IIter, _OIter, _Predicate);
+#endif
+
// count
// count_if
// find_first_of
// find_if
- // for_each
- // generate
- // generate_n
#ifdef __GXX_EXPERIMENTAL_CXX0X__
- template<typename _IIter, typename _Predicate>
- bool
- all_of(_IIter, _IIter, _Predicate);
-
- template<typename _IIter, typename _Predicate>
- bool
- any_of(_IIter, _IIter, _Predicate);
-
- template<typename _IIter, typename _Predicate>
- bool
- none_of(_IIter, _IIter, _Predicate);
-
template<typename _IIter, typename _Predicate>
_IIter
find_if_not(_IIter, _IIter, _Predicate);
#endif
+ // for_each
+ // generate
+ // generate_n
+
template<typename _IIter1, typename _IIter2>
bool
includes(_IIter1, _IIter1, _IIter2, _IIter2);
bool
next_permutation(_BIter, _BIter, _Compare);
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ template<typename _IIter, typename _Predicate>
+ bool
+ none_of(_IIter, _IIter, _Predicate);
+#endif
+
// nth_element
// partial_sort
_RAIter
partial_sort_copy(_IIter, _IIter, _RAIter, _RAIter, _Compare);
+ // partition
+
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ template<typename _IIter, typename _OIter1,
+ typename _OIter2, typename _Predicate>
+ pair<_OIter1, _OIter2>
+ partition_copy(_IIter, _IIter, _OIter1, _OIter2, _Predicate);
+#endif
+
template<typename _RAIter>
void
pop_heap(_RAIter, _RAIter);
}
return __result;
}
+
+ /**
+ * @brief Copy the elements of a sequence to separate output sequences
+ * depending on the truth value of a predicate.
+ * @param first An input iterator.
+ * @param last An input iterator.
+ * @param out_true An output iterator.
+ * @param out_false An output iterator.
+ * @param pred A predicate.
+ * @return A pair designating the ends of the resulting sequences.
+ *
+ * Copies each element in the range @p [first,last) for which
+ * @p pred returns true to the range beginning at @p out_true
+ * and each element for which @p pred returns false to @p out_false.
+ */
+ template<typename _InputIterator, typename _OutputIterator1,
+ typename _OutputIterator2, typename _Predicate>
+ pair<_OutputIterator1, _OutputIterator2>
+ partition_copy(_InputIterator __first, _InputIterator __last,
+ _OutputIterator1 __out_true, _OutputIterator2 __out_false,
+ _Predicate __pred)
+ {
+ // concept requirements
+ __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
+ __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator1,
+ typename iterator_traits<_InputIterator>::value_type>)
+ __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator2,
+ typename iterator_traits<_InputIterator>::value_type>)
+ __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
+ typename iterator_traits<_InputIterator>::value_type>)
+ __glibcxx_requires_valid_range(__first, __last);
+
+ for (; __first != __last; ++__first)
+ if (__pred(*__first))
+ {
+ *__out_true = *__first;
+ ++__out_true;
+ }
+ else
+ {
+ *__out_false = *__first;
+ ++__out_false;
+ }
+
+ return pair<_OutputIterator1, _OutputIterator2>(__out_true, __out_false);
+ }
#endif
/**
template<typename _IIter, typename _OIter, typename _Predicate>
_OIter
copy_if(_IIter, _IIter, _OIter, _Predicate);
+
+ template<typename _IIter, typename _OIter1,
+ typename _OIter2, typename _Predicate>
+ pair<_OIter1, _OIter2>
+ partition_copy(_IIter, _IIter, _OIter1, _OIter2, _Predicate);
#endif
template<typename _FIter>
--- /dev/null
+// { dg-options "-std=gnu++0x" }
+
+// 2008-06-26 Paolo Carlini <paolo.carlini@oracle.com>
+
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+
+using __gnu_test::test_container;
+using __gnu_test::input_iterator_wrapper;
+using __gnu_test::output_iterator_wrapper;
+
+typedef test_container<int, input_iterator_wrapper> Icontainer;
+typedef test_container<int, output_iterator_wrapper> Ocontainer;
+int array[] = {0, 5, 2, 1, 3, 4};
+
+bool
+pred(int i)
+{ return i > 2; }
+
+void
+test1()
+{
+ bool test __attribute__((unused)) = true;
+
+ int true_out[1] = { -1 };
+ int false_out[1] = { -1 };
+ Icontainer in_con(array, array);
+ Ocontainer true_out_con(true_out, true_out);
+ Ocontainer false_out_con(false_out, false_out);
+
+ std::pair<output_iterator_wrapper<int>, output_iterator_wrapper<int> > res =
+ std::partition_copy(in_con.begin(), in_con.end(),
+ true_out_con.begin(), false_out_con.begin(), pred);
+
+ VERIFY( res.first.ptr == true_out );
+ VERIFY( res.second.ptr == false_out );
+}
+
+void
+test2()
+{
+ bool test __attribute__((unused)) = true;
+
+ int true_out[1] = { -1 };
+ int false_out[1] = { -1 };
+ Icontainer in_con(array, array + 2);
+ Ocontainer true_out_con(true_out, true_out + 1);
+ Ocontainer false_out_con(false_out, false_out + 1);
+
+ std::pair<output_iterator_wrapper<int>, output_iterator_wrapper<int> > res =
+ std::partition_copy(in_con.begin(), in_con.end(),
+ true_out_con.begin(), false_out_con.begin(), pred);
+
+ VERIFY( res.first.ptr == true_out + 1 );
+ VERIFY( res.second.ptr == false_out + 1 );
+ VERIFY( true_out[0] == 5 );
+ VERIFY( false_out[0] == 0 );
+}
+
+void
+test3()
+{
+ bool test __attribute__((unused)) = true;
+
+ int true_out[3] = { -1, -1, -1 };
+ int false_out[3] = { -1, -1, -1 };
+ Icontainer in_con(array, array + 6);
+ Ocontainer true_out_con(true_out, true_out + 3);
+ Ocontainer false_out_con(false_out, false_out + 3);
+
+ std::pair<output_iterator_wrapper<int>, output_iterator_wrapper<int> > res =
+ std::partition_copy(in_con.begin(), in_con.end(),
+ true_out_con.begin(), false_out_con.begin(), pred);
+
+ VERIFY( res.first.ptr == true_out + 3 );
+ VERIFY( res.second.ptr == false_out + 3 );
+ VERIFY( true_out[0] == 5 && true_out[1] == 3 && true_out[2] == 4 );
+ VERIFY( false_out[0] == 0 && false_out[1] == 2 && false_out[2] == 1 );
+}
+
+int
+main()
+{
+ test1();
+ test2();
+ test3();
+ return 0;
+}
--- /dev/null
+// 2008-06-26 Paolo Carlini <paolo.carlini@oracle.com>
+
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+
+#include <algorithm>
+#include <testsuite_iterators.h>
+
+using __gnu_test::input_iterator_wrapper;
+using __gnu_test::output_iterator_wrapper;
+
+struct X { };
+
+struct Z1
+{
+ Z1&
+ operator=(const X&)
+ { return *this; }
+};
+
+struct Z2
+{
+ Z2&
+ operator=(const X&)
+ { return *this; }
+};
+
+bool
+pred_function(const X&)
+{ return true; }
+
+struct pred_obj
+{
+ bool
+ operator()(const X&)
+ { return true; }
+};
+
+std::pair<output_iterator_wrapper<Z1>, output_iterator_wrapper<Z2> >
+test1(input_iterator_wrapper<X>& begin,
+ input_iterator_wrapper<X>& end,
+ output_iterator_wrapper<Z1>& true_output,
+ output_iterator_wrapper<Z2>& false_output)
+{ return std::partition_copy(begin, end, true_output, false_output,
+ pred_function); }
+
+std::pair<output_iterator_wrapper<Z1>, output_iterator_wrapper<Z2> >
+test2(input_iterator_wrapper<X>& begin,
+ input_iterator_wrapper<X>& end,
+ output_iterator_wrapper<Z1>& true_output,
+ output_iterator_wrapper<Z2>& false_output)
+{ return std::partition_copy(begin, end, true_output, false_output,
+ pred_obj()); }
--- /dev/null
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+
+// 2008-06-26 Paolo Carlini <paolo.carlini@oracle.com>
+
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+#include <algorithm>
+#include <functional>
+#include <testsuite_api.h>
+
+namespace std
+{
+ using __gnu_test::NonDefaultConstructible;
+
+ typedef NonDefaultConstructible value_type;
+ typedef value_type* iterator_type;
+ typedef std::pointer_to_unary_function<value_type, bool> predicate_type;
+
+ template pair<iterator_type, iterator_type>
+ partition_copy(iterator_type, iterator_type,
+ iterator_type, iterator_type, predicate_type);
+}
--- /dev/null
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+
+// 2008-06-26 Paolo Carlini <paolo.carlini@oracle.com>
+
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+#include <algorithm>
+#include <testsuite_character.h>
+
+namespace std
+{
+ using __gnu_test::pod_int;
+
+ typedef pod_int value_type;
+ typedef value_type* iterator_type;
+ typedef std::pointer_to_unary_function<value_type, bool> predicate_type;
+
+ template pair<iterator_type, iterator_type>
+ partition_copy(iterator_type, iterator_type,
+ iterator_type, iterator_type, predicate_type);
+}