2007-09-12 00:32:51 +02:00
|
|
|
// -*- C++ -*-
|
|
|
|
|
2017-01-01 13:07:43 +01:00
|
|
|
// Copyright (C) 2007-2017 Free Software Foundation, Inc.
|
2007-09-12 00:32:51 +02:00
|
|
|
//
|
|
|
|
// 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
|
2009-04-09 17:00:19 +02:00
|
|
|
// Foundation; either version 3, or (at your option) any later
|
2007-09-12 00:32:51 +02:00
|
|
|
// 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.
|
|
|
|
|
2009-04-09 17:00:19 +02:00
|
|
|
// Under Section 7 of GPL version 3, you are granted additional
|
|
|
|
// permissions described in the GCC Runtime Library Exception, version
|
|
|
|
// 3.1, as published by the Free Software Foundation.
|
2007-09-12 00:32:51 +02:00
|
|
|
|
2009-04-09 17:00:19 +02:00
|
|
|
// You should have received a copy of the GNU General Public License and
|
|
|
|
// a copy of the GCC Runtime Library Exception along with this program;
|
|
|
|
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
|
|
|
// <http://www.gnu.org/licenses/>.
|
2007-09-12 00:32:51 +02:00
|
|
|
|
|
|
|
/** @file parallel/base.h
|
|
|
|
* @brief Sequential helper functions.
|
|
|
|
* This file is a GNU parallel extension to the Standard C++ Library.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Written by Johannes Singler.
|
|
|
|
|
|
|
|
#ifndef _GLIBCXX_PARALLEL_BASE_H
|
|
|
|
#define _GLIBCXX_PARALLEL_BASE_H 1
|
|
|
|
|
2009-12-07 15:27:59 +01:00
|
|
|
#include <bits/c++config.h>
|
|
|
|
#include <bits/stl_function.h>
|
2008-02-18 01:00:00 +01:00
|
|
|
#include <omp.h>
|
|
|
|
#include <parallel/features.h>
|
2007-09-12 00:32:51 +02:00
|
|
|
#include <parallel/basic_iterator.h>
|
|
|
|
#include <parallel/parallel.h>
|
|
|
|
|
2008-02-15 23:55:14 +01:00
|
|
|
// Parallel mode namespaces.
|
2008-03-26 07:27:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @namespace std::__parallel
|
|
|
|
* @brief GNU parallel code, replaces standard behavior with parallel behavior.
|
|
|
|
*/
|
PR libstdc++/36104 part four
2011-01-30 Benjamin Kosnik <bkoz@redhat.com>
PR libstdc++/36104 part four
* include/bits/c++config (_GLIBCXX_STD): Remove.
(_GLIBCXX_STD_D, _GLIBCXX_PR): Now _GLIBCXX_STD_C.
(_GLIBCXX_P): Now _GLIBCXX_STD_A.
(_GLIBCXX_NAMESPACE_DEBUG, _GLIBCXX_NAMESPACE_PARALLEL,
_GLIBCXX_NAMESPACE_PROFILE, _GLIBCXX_NAMESPACE_VERSION): Remove.
(_GLIBCXX_INLINE_DEBUG, _GLIBCXX_INLINE_PARALLEL,
_GLIBCXX_INLINE_PROFILE): Remove.
(_GLIBCXX_BEGIN_NAMESPACE(X)): Remove.
(_GLIBCXX_END_NAMESPACE): Remove.
(_GLIBCXX_BEGIN_NESTED_NAMESPACE(X, Y)): Remove.
(_GLIBCXX_END_NESTED_NAMESPACE): Remove.
(_GLIBCXX_BEGIN_NAMESPACE_ALGO): Add.
(_GLIBCXX_END_NAMESPACE_ALGO): Add.
(_GLIBCXX_BEGIN_NAMESPACE_CONTAINER): Add.
(_GLIBCXX_END_NAMESPACE_CONTAINER): Add.
(_GLIBCXX_BEGIN_NAMESPACE_VERSION): Add.
(_GLIBCXX_END_NAMESPACE_VERSION): Add.
(_GLIBCXX_BEGIN_LDBL_NAMESPACE): To _GLIBCXX_BEGIN_NAMESPACE_LDBL.
(_GLIBCXX_END_LDBL_NAMESPACE): To _GLIBCXX_END_NAMESPACE_LDBL.
(_GLIBCXX_VISIBILITY_ATTR): Revert to _GLIBCXX_VISIBILITY.
* include/*: Use new macros for namespace scope.
* config/*: Same.
* src/*: Same.
* src/Makefile.am (sources): Remove debug_list.cc, add
compatibility-debug_list-2.cc.
(parallel_sources): Remove parallel_list.cc, add
compatibility-parallel_list-2.cc.
(compatibility-parallel_list-2.[o,lo]): New rule.
* src/Makefile.in: Regenerate.
* src/debug_list.cc: Remove.
* src/parallel_list.cc: Remove.
* src/compatibility-list-2.cc: New.
* src/compatibility-debug_list-2.cc: New.
* src/compatibility-parallel_list-2.cc: New.
* doc/doxygen/user.cfg.in: Adjust macros.
* testsuite/20_util/auto_ptr/assign_neg.cc: Adjust line numbers, macros.
* testsuite/20_util/declval/requirements/1_neg.cc: Same.
* testsuite/20_util/duration/requirements/typedefs_neg1.cc: Same.
* testsuite/20_util/duration/requirements/typedefs_neg2.cc: Same.
* testsuite/20_util/duration/requirements/typedefs_neg3.cc: Same.
* testsuite/20_util/forward/c_neg.cc: Same.
* testsuite/20_util/forward/f_neg.cc: Same.
* testsuite/20_util/make_signed/requirements/typedefs_neg.cc: Same.
* testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc: Same.
* testsuite/20_util/ratio/cons/cons_overflow_neg.cc: Same.
* testsuite/20_util/ratio/operations/ops_overflow_neg.cc: Same.
* testsuite/20_util/shared_ptr/cons/43820_neg.cc: Same.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/assign_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/insert_neg.cc: Same.
* testsuite/23_containers/forward_list/capacity/1.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
assign_neg.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
insert_neg.cc: Same.
* testsuite/23_containers/list/capacity/29134.cc: Same.
* testsuite/23_containers/list/requirements/dr438/assign_neg.cc: Same.
* testsuite/23_containers/list/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/list/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/list/requirements/dr438/insert_neg.cc: Same.
* testsuite/23_containers/vector/bool/capacity/29134.cc: Same.
* testsuite/23_containers/vector/bool/modifiers/insert/31370.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/assign_neg.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/insert_neg.cc: Same.
* testsuite/25_algorithms/sort/35588.cc: Same.
* testsuite/27_io/ios_base/cons/assign_neg.cc: Same.
* testsuite/27_io/ios_base/cons/copy_neg.cc: Same.
* testsuite/ext/profile/mutex_extensions_neg.cc: Same.
* testsuite/ext/profile/profiler_algos.cc: Same.
* testsuite/ext/type_traits/add_unsigned_floating_neg.cc: Same.
* testsuite/ext/type_traits/add_unsigned_integer_neg.cc: Same.
* testsuite/ext/type_traits/remove_unsigned_floating_neg.cc: Same.
* testsuite/ext/type_traits/remove_unsigned_integer_neg.cc: Same.
* testsuite/tr1/2_general_utilities/shared_ptr/cons/43820_neg.cc: Same.
From-SVN: r169421
2011-01-30 23:39:36 +01:00
|
|
|
namespace std _GLIBCXX_VISIBILITY(default)
|
2008-02-15 23:55:14 +01:00
|
|
|
{
|
|
|
|
namespace __parallel { }
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @namespace __gnu_parallel
|
2008-03-26 07:27:35 +01:00
|
|
|
* @brief GNU parallel code for public use.
|
2008-02-15 23:55:14 +01:00
|
|
|
*/
|
|
|
|
namespace __gnu_parallel
|
|
|
|
{
|
|
|
|
// Import all the parallel versions of components in namespace std.
|
|
|
|
using namespace std::__parallel;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @namespace __gnu_sequential
|
|
|
|
* @brief GNU sequential classes for public use.
|
|
|
|
*/
|
|
|
|
namespace __gnu_sequential
|
|
|
|
{
|
2008-02-18 01:00:00 +01:00
|
|
|
// Import whatever is the serial version.
|
2008-02-15 23:55:14 +01:00
|
|
|
#ifdef _GLIBCXX_PARALLEL
|
PR libstdc++/36104 part four
2011-01-30 Benjamin Kosnik <bkoz@redhat.com>
PR libstdc++/36104 part four
* include/bits/c++config (_GLIBCXX_STD): Remove.
(_GLIBCXX_STD_D, _GLIBCXX_PR): Now _GLIBCXX_STD_C.
(_GLIBCXX_P): Now _GLIBCXX_STD_A.
(_GLIBCXX_NAMESPACE_DEBUG, _GLIBCXX_NAMESPACE_PARALLEL,
_GLIBCXX_NAMESPACE_PROFILE, _GLIBCXX_NAMESPACE_VERSION): Remove.
(_GLIBCXX_INLINE_DEBUG, _GLIBCXX_INLINE_PARALLEL,
_GLIBCXX_INLINE_PROFILE): Remove.
(_GLIBCXX_BEGIN_NAMESPACE(X)): Remove.
(_GLIBCXX_END_NAMESPACE): Remove.
(_GLIBCXX_BEGIN_NESTED_NAMESPACE(X, Y)): Remove.
(_GLIBCXX_END_NESTED_NAMESPACE): Remove.
(_GLIBCXX_BEGIN_NAMESPACE_ALGO): Add.
(_GLIBCXX_END_NAMESPACE_ALGO): Add.
(_GLIBCXX_BEGIN_NAMESPACE_CONTAINER): Add.
(_GLIBCXX_END_NAMESPACE_CONTAINER): Add.
(_GLIBCXX_BEGIN_NAMESPACE_VERSION): Add.
(_GLIBCXX_END_NAMESPACE_VERSION): Add.
(_GLIBCXX_BEGIN_LDBL_NAMESPACE): To _GLIBCXX_BEGIN_NAMESPACE_LDBL.
(_GLIBCXX_END_LDBL_NAMESPACE): To _GLIBCXX_END_NAMESPACE_LDBL.
(_GLIBCXX_VISIBILITY_ATTR): Revert to _GLIBCXX_VISIBILITY.
* include/*: Use new macros for namespace scope.
* config/*: Same.
* src/*: Same.
* src/Makefile.am (sources): Remove debug_list.cc, add
compatibility-debug_list-2.cc.
(parallel_sources): Remove parallel_list.cc, add
compatibility-parallel_list-2.cc.
(compatibility-parallel_list-2.[o,lo]): New rule.
* src/Makefile.in: Regenerate.
* src/debug_list.cc: Remove.
* src/parallel_list.cc: Remove.
* src/compatibility-list-2.cc: New.
* src/compatibility-debug_list-2.cc: New.
* src/compatibility-parallel_list-2.cc: New.
* doc/doxygen/user.cfg.in: Adjust macros.
* testsuite/20_util/auto_ptr/assign_neg.cc: Adjust line numbers, macros.
* testsuite/20_util/declval/requirements/1_neg.cc: Same.
* testsuite/20_util/duration/requirements/typedefs_neg1.cc: Same.
* testsuite/20_util/duration/requirements/typedefs_neg2.cc: Same.
* testsuite/20_util/duration/requirements/typedefs_neg3.cc: Same.
* testsuite/20_util/forward/c_neg.cc: Same.
* testsuite/20_util/forward/f_neg.cc: Same.
* testsuite/20_util/make_signed/requirements/typedefs_neg.cc: Same.
* testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc: Same.
* testsuite/20_util/ratio/cons/cons_overflow_neg.cc: Same.
* testsuite/20_util/ratio/operations/ops_overflow_neg.cc: Same.
* testsuite/20_util/shared_ptr/cons/43820_neg.cc: Same.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/assign_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/insert_neg.cc: Same.
* testsuite/23_containers/forward_list/capacity/1.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
assign_neg.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
insert_neg.cc: Same.
* testsuite/23_containers/list/capacity/29134.cc: Same.
* testsuite/23_containers/list/requirements/dr438/assign_neg.cc: Same.
* testsuite/23_containers/list/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/list/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/list/requirements/dr438/insert_neg.cc: Same.
* testsuite/23_containers/vector/bool/capacity/29134.cc: Same.
* testsuite/23_containers/vector/bool/modifiers/insert/31370.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/assign_neg.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/insert_neg.cc: Same.
* testsuite/25_algorithms/sort/35588.cc: Same.
* testsuite/27_io/ios_base/cons/assign_neg.cc: Same.
* testsuite/27_io/ios_base/cons/copy_neg.cc: Same.
* testsuite/ext/profile/mutex_extensions_neg.cc: Same.
* testsuite/ext/profile/profiler_algos.cc: Same.
* testsuite/ext/type_traits/add_unsigned_floating_neg.cc: Same.
* testsuite/ext/type_traits/add_unsigned_integer_neg.cc: Same.
* testsuite/ext/type_traits/remove_unsigned_floating_neg.cc: Same.
* testsuite/ext/type_traits/remove_unsigned_integer_neg.cc: Same.
* testsuite/tr1/2_general_utilities/shared_ptr/cons/43820_neg.cc: Same.
From-SVN: r169421
2011-01-30 23:39:36 +01:00
|
|
|
using namespace std::_GLIBCXX_STD_A;
|
2008-02-15 23:55:14 +01:00
|
|
|
#else
|
|
|
|
using namespace std;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-12 00:32:51 +02:00
|
|
|
namespace __gnu_parallel
|
|
|
|
{
|
2008-02-18 01:00:00 +01:00
|
|
|
// NB: Including this file cannot produce (unresolved) symbols from
|
|
|
|
// the OpenMP runtime unless the parallel mode is actually invoked
|
|
|
|
// and active, which imples that the OpenMP runtime is actually
|
|
|
|
// going to be linked in.
|
2009-11-09 17:36:59 +01:00
|
|
|
inline _ThreadIndex
|
2009-09-16 11:47:25 +02:00
|
|
|
__get_max_threads()
|
2008-02-18 01:00:00 +01:00
|
|
|
{
|
2009-11-09 17:36:59 +01:00
|
|
|
_ThreadIndex __i = omp_get_max_threads();
|
2008-02-18 01:00:00 +01:00
|
|
|
return __i > 1 ? __i : 1;
|
|
|
|
}
|
|
|
|
|
2009-09-25 10:37:18 +02:00
|
|
|
|
2008-02-18 01:00:00 +01:00
|
|
|
inline bool
|
2009-09-16 11:47:25 +02:00
|
|
|
__is_parallel(const _Parallelism __p) { return __p != sequential; }
|
2008-02-18 01:00:00 +01:00
|
|
|
|
|
|
|
|
2009-11-06 23:15:17 +01:00
|
|
|
/** @brief Calculates the rounded-down logarithm of @c __n for base 2.
|
2009-11-05 15:06:13 +01:00
|
|
|
* @param __n Argument.
|
|
|
|
* @return Returns 0 for any argument <1.
|
|
|
|
*/
|
|
|
|
template<typename _Size>
|
|
|
|
inline _Size
|
|
|
|
__rd_log2(_Size __n)
|
2007-09-12 00:32:51 +02:00
|
|
|
{
|
2009-09-16 11:47:25 +02:00
|
|
|
_Size __k;
|
|
|
|
for (__k = 0; __n > 1; __n >>= 1)
|
|
|
|
++__k;
|
|
|
|
return __k;
|
2007-09-12 00:32:51 +02:00
|
|
|
}
|
|
|
|
|
2009-11-05 15:06:13 +01:00
|
|
|
/** @brief Encode two integers into one gnu_parallel::_CASable.
|
2009-11-06 23:15:17 +01:00
|
|
|
* @param __a First integer, to be encoded in the most-significant @c
|
2009-11-05 15:06:13 +01:00
|
|
|
* _CASable_bits/2 bits.
|
|
|
|
* @param __b Second integer, to be encoded in the least-significant
|
2009-11-06 23:15:17 +01:00
|
|
|
* @c _CASable_bits/2 bits.
|
|
|
|
* @return value encoding @c __a and @c __b.
|
2010-01-12 01:51:50 +01:00
|
|
|
* @see __decode2
|
2009-11-05 15:06:13 +01:00
|
|
|
*/
|
|
|
|
inline _CASable
|
|
|
|
__encode2(int __a, int __b) //must all be non-negative, actually
|
2007-09-12 00:32:51 +02:00
|
|
|
{
|
2009-11-05 15:06:13 +01:00
|
|
|
return (((_CASable)__a) << (_CASable_bits / 2)) | (((_CASable)__b) << 0);
|
|
|
|
}
|
2007-09-12 00:32:51 +02:00
|
|
|
|
2009-11-05 15:06:13 +01:00
|
|
|
/** @brief Decode two integers from one gnu_parallel::_CASable.
|
|
|
|
* @param __x __gnu_parallel::_CASable to decode integers from.
|
|
|
|
* @param __a First integer, to be decoded from the most-significant
|
2009-11-06 23:15:17 +01:00
|
|
|
* @c _CASable_bits/2 bits of @c __x.
|
2009-11-05 15:06:13 +01:00
|
|
|
* @param __b Second integer, to be encoded in the least-significant
|
2009-11-06 23:15:17 +01:00
|
|
|
* @c _CASable_bits/2 bits of @c __x.
|
2009-11-05 15:06:13 +01:00
|
|
|
* @see __encode2
|
|
|
|
*/
|
|
|
|
inline void
|
2010-01-12 01:51:50 +01:00
|
|
|
__decode2(_CASable __x, int& __a, int& __b)
|
2009-11-05 15:06:13 +01:00
|
|
|
{
|
|
|
|
__a = (int)((__x >> (_CASable_bits / 2)) & _CASable_mask);
|
|
|
|
__b = (int)((__x >> 0 ) & _CASable_mask);
|
|
|
|
}
|
2007-09-12 00:32:51 +02:00
|
|
|
|
2009-11-05 15:06:13 +01:00
|
|
|
//needed for parallel "numeric", even if "algorithm" not included
|
2007-09-12 00:32:51 +02:00
|
|
|
|
2009-11-05 15:06:13 +01:00
|
|
|
/** @brief Equivalent to std::min. */
|
|
|
|
template<typename _Tp>
|
2010-06-13 17:44:51 +02:00
|
|
|
inline const _Tp&
|
2009-11-05 15:06:13 +01:00
|
|
|
min(const _Tp& __a, const _Tp& __b)
|
|
|
|
{ return (__a < __b) ? __a : __b; }
|
2007-09-12 00:32:51 +02:00
|
|
|
|
2009-11-05 15:06:13 +01:00
|
|
|
/** @brief Equivalent to std::max. */
|
|
|
|
template<typename _Tp>
|
2010-06-13 17:44:51 +02:00
|
|
|
inline const _Tp&
|
2009-11-05 15:06:13 +01:00
|
|
|
max(const _Tp& __a, const _Tp& __b)
|
|
|
|
{ return (__a > __b) ? __a : __b; }
|
|
|
|
|
|
|
|
/** @brief Constructs predicate for equality from strict weak
|
|
|
|
* ordering predicate
|
|
|
|
*/
|
|
|
|
template<typename _T1, typename _T2, typename _Compare>
|
|
|
|
class _EqualFromLess : public std::binary_function<_T1, _T2, bool>
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
_Compare& _M_comp;
|
2007-11-22 11:13:08 +01:00
|
|
|
|
2009-11-05 15:06:13 +01:00
|
|
|
public:
|
|
|
|
_EqualFromLess(_Compare& __comp) : _M_comp(__comp) { }
|
2007-10-08 23:14:45 +02:00
|
|
|
|
2009-11-05 15:06:13 +01:00
|
|
|
bool operator()(const _T1& __a, const _T2& __b)
|
|
|
|
{ return !_M_comp(__a, __b) && !_M_comp(__b, __a); }
|
|
|
|
};
|
2007-09-12 00:32:51 +02:00
|
|
|
|
2007-10-08 23:14:45 +02:00
|
|
|
|
2010-01-18 09:44:45 +01:00
|
|
|
/** @brief Similar to std::unary_negate,
|
2009-11-05 15:06:13 +01:00
|
|
|
* but giving the argument types explicitly. */
|
|
|
|
template<typename _Predicate, typename argument_type>
|
|
|
|
class __unary_negate
|
|
|
|
: public std::unary_function<argument_type, bool>
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
_Predicate _M_pred;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit
|
|
|
|
__unary_negate(const _Predicate& __x) : _M_pred(__x) { }
|
|
|
|
|
|
|
|
bool
|
|
|
|
operator()(const argument_type& __x)
|
|
|
|
{ return !_M_pred(__x); }
|
|
|
|
};
|
|
|
|
|
|
|
|
/** @brief Similar to std::binder1st,
|
|
|
|
* but giving the argument types explicitly. */
|
|
|
|
template<typename _Operation, typename _FirstArgumentType,
|
|
|
|
typename _SecondArgumentType, typename _ResultType>
|
|
|
|
class __binder1st
|
|
|
|
: public std::unary_function<_SecondArgumentType, _ResultType>
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
_Operation _M_op;
|
|
|
|
_FirstArgumentType _M_value;
|
|
|
|
|
|
|
|
public:
|
|
|
|
__binder1st(const _Operation& __x, const _FirstArgumentType& __y)
|
|
|
|
: _M_op(__x), _M_value(__y) { }
|
|
|
|
|
|
|
|
_ResultType
|
|
|
|
operator()(const _SecondArgumentType& __x)
|
|
|
|
{ return _M_op(_M_value, __x); }
|
|
|
|
|
|
|
|
// _GLIBCXX_RESOLVE_LIB_DEFECTS
|
|
|
|
// 109. Missing binders for non-const sequence elements
|
|
|
|
_ResultType
|
|
|
|
operator()(_SecondArgumentType& __x) const
|
|
|
|
{ return _M_op(_M_value, __x); }
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Similar to std::binder2nd, but giving the argument types
|
|
|
|
* explicitly.
|
|
|
|
*/
|
|
|
|
template<typename _Operation, typename _FirstArgumentType,
|
|
|
|
typename _SecondArgumentType, typename _ResultType>
|
2010-01-12 01:51:50 +01:00
|
|
|
class __binder2nd
|
2009-11-05 15:06:13 +01:00
|
|
|
: public std::unary_function<_FirstArgumentType, _ResultType>
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
_Operation _M_op;
|
|
|
|
_SecondArgumentType _M_value;
|
|
|
|
|
|
|
|
public:
|
2010-01-12 01:51:50 +01:00
|
|
|
__binder2nd(const _Operation& __x, const _SecondArgumentType& __y)
|
2009-11-05 15:06:13 +01:00
|
|
|
: _M_op(__x), _M_value(__y) { }
|
|
|
|
|
|
|
|
_ResultType
|
|
|
|
operator()(const _FirstArgumentType& __x) const
|
|
|
|
{ return _M_op(__x, _M_value); }
|
|
|
|
|
|
|
|
// _GLIBCXX_RESOLVE_LIB_DEFECTS
|
|
|
|
// 109. Missing binders for non-const sequence elements
|
|
|
|
_ResultType
|
|
|
|
operator()(_FirstArgumentType& __x)
|
|
|
|
{ return _M_op(__x, _M_value); }
|
|
|
|
};
|
|
|
|
|
|
|
|
/** @brief Similar to std::equal_to, but allows two different types. */
|
|
|
|
template<typename _T1, typename _T2>
|
|
|
|
struct _EqualTo : std::binary_function<_T1, _T2, bool>
|
|
|
|
{
|
|
|
|
bool operator()(const _T1& __t1, const _T2& __t2) const
|
|
|
|
{ return __t1 == __t2; }
|
|
|
|
};
|
2007-10-08 23:14:45 +02:00
|
|
|
|
2009-11-05 15:06:13 +01:00
|
|
|
/** @brief Similar to std::less, but allows two different types. */
|
|
|
|
template<typename _T1, typename _T2>
|
|
|
|
struct _Less : std::binary_function<_T1, _T2, bool>
|
|
|
|
{
|
|
|
|
bool
|
|
|
|
operator()(const _T1& __t1, const _T2& __t2) const
|
|
|
|
{ return __t1 < __t2; }
|
|
|
|
|
|
|
|
bool
|
|
|
|
operator()(const _T2& __t2, const _T1& __t1) const
|
|
|
|
{ return __t2 < __t1; }
|
|
|
|
};
|
|
|
|
|
|
|
|
// Partial specialization for one type. Same as std::less.
|
|
|
|
template<typename _Tp>
|
2010-03-22 13:18:46 +01:00
|
|
|
struct _Less<_Tp, _Tp>
|
|
|
|
: public std::less<_Tp> { };
|
2007-10-08 23:14:45 +02:00
|
|
|
|
2009-11-05 15:06:13 +01:00
|
|
|
/** @brief Similar to std::plus, but allows two different types. */
|
2010-03-22 13:18:46 +01:00
|
|
|
template<typename _Tp1, typename _Tp2, typename _Result
|
2010-06-03 21:15:56 +02:00
|
|
|
= __typeof__(*static_cast<_Tp1*>(0)
|
|
|
|
+ *static_cast<_Tp2*>(0))>
|
2010-03-22 13:18:46 +01:00
|
|
|
struct _Plus : public std::binary_function<_Tp1, _Tp2, _Result>
|
2009-11-05 15:06:13 +01:00
|
|
|
{
|
2010-03-22 13:18:46 +01:00
|
|
|
_Result
|
2009-11-05 15:06:13 +01:00
|
|
|
operator()(const _Tp1& __x, const _Tp2& __y) const
|
|
|
|
{ return __x + __y; }
|
|
|
|
};
|
2007-10-08 23:14:45 +02:00
|
|
|
|
2009-11-05 15:06:13 +01:00
|
|
|
// Partial specialization for one type. Same as std::plus.
|
|
|
|
template<typename _Tp>
|
2010-03-22 13:18:46 +01:00
|
|
|
struct _Plus<_Tp, _Tp, _Tp>
|
|
|
|
: public std::plus<_Tp> { };
|
2007-10-08 23:14:45 +02:00
|
|
|
|
2009-11-05 15:06:13 +01:00
|
|
|
/** @brief Similar to std::multiplies, but allows two different types. */
|
2010-03-22 13:18:46 +01:00
|
|
|
template<typename _Tp1, typename _Tp2, typename _Result
|
2010-06-03 21:15:56 +02:00
|
|
|
= __typeof__(*static_cast<_Tp1*>(0)
|
|
|
|
* *static_cast<_Tp2*>(0))>
|
2010-03-22 13:18:46 +01:00
|
|
|
struct _Multiplies : public std::binary_function<_Tp1, _Tp2, _Result>
|
2009-11-05 15:06:13 +01:00
|
|
|
{
|
2010-03-22 13:18:46 +01:00
|
|
|
_Result
|
2009-11-05 15:06:13 +01:00
|
|
|
operator()(const _Tp1& __x, const _Tp2& __y) const
|
|
|
|
{ return __x * __y; }
|
|
|
|
};
|
2007-10-08 23:14:45 +02:00
|
|
|
|
2009-11-05 15:06:13 +01:00
|
|
|
// Partial specialization for one type. Same as std::multiplies.
|
|
|
|
template<typename _Tp>
|
2010-03-22 13:18:46 +01:00
|
|
|
struct _Multiplies<_Tp, _Tp, _Tp>
|
|
|
|
: public std::multiplies<_Tp> { };
|
2007-09-12 00:32:51 +02:00
|
|
|
|
2009-11-05 15:06:13 +01:00
|
|
|
/** @brief _Iterator associated with __gnu_parallel::_PseudoSequence.
|
|
|
|
* If features the usual random-access iterator functionality.
|
|
|
|
* @param _Tp Sequence _M_value type.
|
2010-06-13 17:44:51 +02:00
|
|
|
* @param _DifferenceTp Sequence difference type.
|
2009-11-05 15:06:13 +01:00
|
|
|
*/
|
|
|
|
template<typename _Tp, typename _DifferenceTp>
|
|
|
|
class _PseudoSequenceIterator
|
2007-09-12 00:32:51 +02:00
|
|
|
{
|
2009-11-05 15:06:13 +01:00
|
|
|
public:
|
|
|
|
typedef _DifferenceTp _DifferenceType;
|
2007-09-12 00:32:51 +02:00
|
|
|
|
2009-11-05 15:06:13 +01:00
|
|
|
_PseudoSequenceIterator(const _Tp& __val, _DifferenceType __pos)
|
|
|
|
: _M_val(__val), _M_pos(__pos) { }
|
2007-09-12 00:32:51 +02:00
|
|
|
|
2009-11-05 15:06:13 +01:00
|
|
|
// Pre-increment operator.
|
|
|
|
_PseudoSequenceIterator&
|
|
|
|
operator++()
|
|
|
|
{
|
|
|
|
++_M_pos;
|
|
|
|
return *this;
|
|
|
|
}
|
2007-09-12 00:32:51 +02:00
|
|
|
|
2009-11-05 15:06:13 +01:00
|
|
|
// Post-increment operator.
|
2010-03-22 14:55:11 +01:00
|
|
|
_PseudoSequenceIterator
|
2009-11-05 15:06:13 +01:00
|
|
|
operator++(int)
|
|
|
|
{ return _PseudoSequenceIterator(_M_pos++); }
|
|
|
|
|
|
|
|
const _Tp&
|
|
|
|
operator*() const
|
|
|
|
{ return _M_val; }
|
|
|
|
|
|
|
|
const _Tp&
|
|
|
|
operator[](_DifferenceType) const
|
|
|
|
{ return _M_val; }
|
|
|
|
|
|
|
|
bool
|
|
|
|
operator==(const _PseudoSequenceIterator& __i2)
|
|
|
|
{ return _M_pos == __i2._M_pos; }
|
|
|
|
|
2010-03-22 14:55:11 +01:00
|
|
|
bool
|
2009-11-05 15:06:13 +01:00
|
|
|
operator!=(const _PseudoSequenceIterator& __i2)
|
|
|
|
{ return _M_pos != __i2._M_pos; }
|
|
|
|
|
|
|
|
_DifferenceType
|
|
|
|
operator-(const _PseudoSequenceIterator& __i2)
|
|
|
|
{ return _M_pos - __i2._M_pos; }
|
2010-03-22 14:55:11 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
const _Tp& _M_val;
|
|
|
|
_DifferenceType _M_pos;
|
2009-11-05 15:06:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/** @brief Sequence that conceptually consists of multiple copies of
|
|
|
|
the same element.
|
|
|
|
* The copies are not stored explicitly, of course.
|
|
|
|
* @param _Tp Sequence _M_value type.
|
2010-06-13 17:44:51 +02:00
|
|
|
* @param _DifferenceTp Sequence difference type.
|
2007-11-22 11:13:08 +01:00
|
|
|
*/
|
2009-11-05 15:06:13 +01:00
|
|
|
template<typename _Tp, typename _DifferenceTp>
|
|
|
|
class _PseudoSequence
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef _DifferenceTp _DifferenceType;
|
|
|
|
|
|
|
|
// Better cast down to uint64_t, than up to _DifferenceTp.
|
|
|
|
typedef _PseudoSequenceIterator<_Tp, uint64_t> iterator;
|
|
|
|
|
|
|
|
/** @brief Constructor.
|
2011-08-07 09:27:06 +02:00
|
|
|
* @param __val Element of the sequence.
|
2009-11-05 15:06:13 +01:00
|
|
|
* @param __count Number of (virtual) copies.
|
|
|
|
*/
|
|
|
|
_PseudoSequence(const _Tp& __val, _DifferenceType __count)
|
|
|
|
: _M_val(__val), _M_count(__count) { }
|
|
|
|
|
|
|
|
/** @brief Begin iterator. */
|
|
|
|
iterator
|
|
|
|
begin() const
|
|
|
|
{ return iterator(_M_val, 0); }
|
|
|
|
|
|
|
|
/** @brief End iterator. */
|
|
|
|
iterator
|
|
|
|
end() const
|
|
|
|
{ return iterator(_M_val, _M_count); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
const _Tp& _M_val;
|
|
|
|
_DifferenceType _M_count;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** @brief Compute the median of three referenced elements,
|
2009-11-06 23:15:17 +01:00
|
|
|
according to @c __comp.
|
2009-11-05 15:06:13 +01:00
|
|
|
* @param __a First iterator.
|
|
|
|
* @param __b Second iterator.
|
|
|
|
* @param __c Third iterator.
|
|
|
|
* @param __comp Comparator.
|
|
|
|
*/
|
|
|
|
template<typename _RAIter, typename _Compare>
|
|
|
|
_RAIter
|
|
|
|
__median_of_three_iterators(_RAIter __a, _RAIter __b,
|
2010-03-22 14:55:11 +01:00
|
|
|
_RAIter __c, _Compare __comp)
|
2009-11-05 15:06:13 +01:00
|
|
|
{
|
|
|
|
if (__comp(*__a, *__b))
|
|
|
|
if (__comp(*__b, *__c))
|
|
|
|
return __b;
|
|
|
|
else
|
|
|
|
if (__comp(*__a, *__c))
|
|
|
|
return __c;
|
|
|
|
else
|
|
|
|
return __a;
|
2007-09-12 00:32:51 +02:00
|
|
|
else
|
2009-11-05 15:06:13 +01:00
|
|
|
{
|
|
|
|
// Just swap __a and __b.
|
|
|
|
if (__comp(*__a, *__c))
|
|
|
|
return __a;
|
|
|
|
else
|
|
|
|
if (__comp(*__b, *__c))
|
|
|
|
return __c;
|
|
|
|
else
|
|
|
|
return __b;
|
|
|
|
}
|
|
|
|
}
|
2007-09-12 00:32:51 +02:00
|
|
|
|
2016-12-08 13:08:14 +01:00
|
|
|
#if _GLIBCXX_PARALLEL_ASSERTIONS && defined(__glibcxx_assert_impl)
|
|
|
|
#define _GLIBCXX_PARALLEL_ASSERT(_Condition) __glibcxx_assert_impl(_Condition)
|
|
|
|
#else
|
|
|
|
#define _GLIBCXX_PARALLEL_ASSERT(_Condition)
|
|
|
|
#endif
|
2007-11-22 11:13:08 +01:00
|
|
|
|
2007-09-12 00:32:51 +02:00
|
|
|
} //namespace __gnu_parallel
|
|
|
|
|
2008-07-15 12:06:58 +02:00
|
|
|
#endif /* _GLIBCXX_PARALLEL_BASE_H */
|