2007-09-12 00:32:51 +02:00
|
|
|
// -*- C++ -*-
|
|
|
|
|
2008-01-10 03:07:41 +01:00
|
|
|
// Copyright (C) 2007, 2008 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
|
|
|
|
// 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, 59 Temple Place - Suite 330, Boston,
|
|
|
|
// MA 02111-1307, 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.
|
|
|
|
|
|
|
|
/** @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
|
|
|
|
|
2008-02-18 01:00:00 +01:00
|
|
|
#include <cstdio>
|
2007-09-12 00:32:51 +02:00
|
|
|
#include <functional>
|
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.
|
|
|
|
*/
|
2008-02-15 23:55:14 +01:00
|
|
|
namespace std
|
|
|
|
{
|
|
|
|
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
|
|
|
|
using namespace std::__norm;
|
|
|
|
#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.
|
|
|
|
inline int
|
|
|
|
get_max_threads()
|
|
|
|
{
|
|
|
|
int __i = omp_get_max_threads();
|
|
|
|
return __i > 1 ? __i : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
is_parallel(const _Parallelism __p) { return __p != sequential; }
|
|
|
|
|
|
|
|
|
2007-09-12 00:32:51 +02:00
|
|
|
// XXX remove std::duplicates from here if possible,
|
|
|
|
// XXX but keep minimal dependencies.
|
|
|
|
|
2007-11-22 11:13:08 +01:00
|
|
|
/** @brief Calculates the rounded-down logarithm of @c n for base 2.
|
|
|
|
* @param n Argument.
|
2008-09-19 13:37:16 +02:00
|
|
|
* @return Returns 0 for any argument <1.
|
2007-11-22 11:13:08 +01:00
|
|
|
*/
|
|
|
|
template<typename Size>
|
|
|
|
inline Size
|
2008-09-19 13:37:16 +02:00
|
|
|
__log2(Size n)
|
2007-09-12 00:32:51 +02:00
|
|
|
{
|
|
|
|
Size k;
|
2008-09-19 13:37:16 +02:00
|
|
|
for (k = 0; n > 1; n >>= 1)
|
2007-11-22 11:13:08 +01:00
|
|
|
++k;
|
2007-09-12 00:32:51 +02:00
|
|
|
return k;
|
|
|
|
}
|
|
|
|
|
2007-11-22 11:13:08 +01:00
|
|
|
/** @brief Encode two integers into one __gnu_parallel::lcas_t.
|
|
|
|
* @param a First integer, to be encoded in the most-significant @c
|
|
|
|
* lcas_t_bits/2 bits.
|
|
|
|
* @param b Second integer, to be encoded in the least-significant
|
|
|
|
* @c lcas_t_bits/2 bits.
|
|
|
|
* @return __gnu_parallel::lcas_t value encoding @c a and @c b.
|
|
|
|
* @see decode2
|
|
|
|
*/
|
|
|
|
inline lcas_t
|
|
|
|
encode2(int a, int b) //must all be non-negative, actually
|
|
|
|
{
|
|
|
|
return (((lcas_t)a) << (lcas_t_bits / 2)) | (((lcas_t)b) << 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @brief Decode two integers from one __gnu_parallel::lcas_t.
|
|
|
|
* @param x __gnu_parallel::lcas_t to decode integers from.
|
|
|
|
* @param a First integer, to be decoded from the most-significant
|
|
|
|
* @c lcas_t_bits/2 bits of @c x.
|
|
|
|
* @param b Second integer, to be encoded in the least-significant
|
|
|
|
* @c lcas_t_bits/2 bits of @c x.
|
|
|
|
* @see encode2
|
|
|
|
*/
|
|
|
|
inline void
|
|
|
|
decode2(lcas_t x, int& a, int& b)
|
|
|
|
{
|
|
|
|
a = (int)((x >> (lcas_t_bits / 2)) & lcas_t_mask);
|
|
|
|
b = (int)((x >> 0 ) & lcas_t_mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @brief Equivalent to std::min. */
|
|
|
|
template<typename T>
|
|
|
|
const T&
|
|
|
|
min(const T& a, const T& b)
|
2008-01-10 03:07:41 +01:00
|
|
|
{ return (a < b) ? a : b; }
|
2007-09-12 00:32:51 +02:00
|
|
|
|
2007-11-22 11:13:08 +01:00
|
|
|
/** @brief Equivalent to std::max. */
|
|
|
|
template<typename T>
|
|
|
|
const T&
|
|
|
|
max(const T& a, const T& b)
|
2008-01-10 03:07:41 +01:00
|
|
|
{ return (a > b) ? a : b; }
|
2007-09-12 00:32:51 +02:00
|
|
|
|
2007-11-22 11:13:08 +01:00
|
|
|
/** @brief Constructs predicate for equality from strict weak
|
|
|
|
* ordering predicate
|
|
|
|
*/
|
|
|
|
// XXX comparator at the end, as per others
|
|
|
|
template<typename Comparator, typename T1, typename T2>
|
2007-09-12 00:32:51 +02:00
|
|
|
class equal_from_less : public std::binary_function<T1, T2, bool>
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
Comparator& comp;
|
|
|
|
|
|
|
|
public:
|
|
|
|
equal_from_less(Comparator& _comp) : comp(_comp) { }
|
|
|
|
|
|
|
|
bool operator()(const T1& a, const T2& b)
|
|
|
|
{
|
|
|
|
return !comp(a, b) && !comp(b, a);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-11-22 11:13:08 +01:00
|
|
|
/** @brief Similar to std::binder1st,
|
|
|
|
* 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. */
|
2008-02-18 01:00:00 +01:00
|
|
|
template<typename _Operation, typename first_argument_type,
|
|
|
|
typename second_argument_type, typename result_type>
|
2007-11-22 11:13:08 +01:00
|
|
|
class binder1st
|
|
|
|
: public std::unary_function<second_argument_type, result_type>
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
_Operation op;
|
|
|
|
first_argument_type value;
|
|
|
|
|
|
|
|
public:
|
|
|
|
binder1st(const _Operation& __x,
|
|
|
|
const first_argument_type& __y)
|
|
|
|
: op(__x), value(__y) { }
|
|
|
|
|
|
|
|
result_type
|
|
|
|
operator()(const second_argument_type& __x)
|
|
|
|
{ return op(value, __x); }
|
|
|
|
|
|
|
|
// _GLIBCXX_RESOLVE_LIB_DEFECTS
|
|
|
|
// 109. Missing binders for non-const sequence elements
|
|
|
|
result_type
|
|
|
|
operator()(second_argument_type& __x) const
|
|
|
|
{ return op(value, __x); }
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Similar to std::binder2nd, but giving the argument types
|
|
|
|
* explicitly.
|
|
|
|
*/
|
2008-02-18 01:00:00 +01:00
|
|
|
template<typename _Operation, typename first_argument_type,
|
|
|
|
typename second_argument_type, typename result_type>
|
2007-11-22 11:13:08 +01:00
|
|
|
class binder2nd
|
|
|
|
: public std::unary_function<first_argument_type, result_type>
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
_Operation op;
|
|
|
|
second_argument_type value;
|
|
|
|
|
|
|
|
public:
|
|
|
|
binder2nd(const _Operation& __x,
|
|
|
|
const second_argument_type& __y)
|
|
|
|
: op(__x), value(__y) { }
|
|
|
|
|
|
|
|
result_type
|
|
|
|
operator()(const first_argument_type& __x) const
|
|
|
|
{ return op(__x, value); }
|
|
|
|
|
|
|
|
// _GLIBCXX_RESOLVE_LIB_DEFECTS
|
|
|
|
// 109. Missing binders for non-const sequence elements
|
|
|
|
result_type
|
|
|
|
operator()(first_argument_type& __x)
|
|
|
|
{ return op(__x, value); }
|
|
|
|
};
|
|
|
|
|
|
|
|
/** @brief Similar to std::equal_to, but allows two different types. */
|
|
|
|
template<typename T1, typename T2>
|
2007-10-08 23:14:45 +02:00
|
|
|
struct equal_to : std::binary_function<T1, T2, bool>
|
|
|
|
{
|
|
|
|
bool operator()(const T1& t1, const T2& t2) const
|
|
|
|
{ return t1 == t2; }
|
|
|
|
};
|
|
|
|
|
2007-11-22 11:13:08 +01:00
|
|
|
/** @brief Similar to std::less, but allows two different types. */
|
|
|
|
template<typename T1, typename T2>
|
2007-09-12 00:32:51 +02:00
|
|
|
struct less : std::binary_function<T1, T2, bool>
|
|
|
|
{
|
2007-11-22 11:13:08 +01:00
|
|
|
bool
|
2007-09-14 22:37:25 +02:00
|
|
|
operator()(const T1& t1, const T2& t2) const
|
2007-09-12 00:32:51 +02:00
|
|
|
{ return t1 < t2; }
|
2007-09-14 22:37:25 +02:00
|
|
|
|
2007-11-22 11:13:08 +01:00
|
|
|
bool
|
2007-09-14 22:37:25 +02:00
|
|
|
operator()(const T2& t2, const T1& t1) const
|
|
|
|
{ return t2 < t1; }
|
2007-09-12 00:32:51 +02:00
|
|
|
};
|
|
|
|
|
2007-11-22 11:13:08 +01:00
|
|
|
// Partial specialization for one type. Same as std::less.
|
|
|
|
template<typename _Tp>
|
|
|
|
struct less<_Tp, _Tp> : public std::binary_function<_Tp, _Tp, bool>
|
|
|
|
{
|
|
|
|
bool
|
|
|
|
operator()(const _Tp& __x, const _Tp& __y) const
|
|
|
|
{ return __x < __y; }
|
|
|
|
};
|
2007-09-12 00:32:51 +02:00
|
|
|
|
2007-10-08 23:14:45 +02:00
|
|
|
|
2007-11-22 11:13:08 +01:00
|
|
|
/** @brief Similar to std::plus, but allows two different types. */
|
|
|
|
template<typename _Tp1, typename _Tp2>
|
|
|
|
struct plus : public std::binary_function<_Tp1, _Tp2, _Tp1>
|
|
|
|
{
|
2008-06-26 12:45:31 +02:00
|
|
|
typedef __typeof__(*static_cast<_Tp1*>(NULL)
|
|
|
|
+ *static_cast<_Tp2*>(NULL)) result;
|
2007-10-08 23:14:45 +02:00
|
|
|
|
2007-11-22 11:13:08 +01:00
|
|
|
result
|
|
|
|
operator()(const _Tp1& __x, const _Tp2& __y) const
|
|
|
|
{ return __x + __y; }
|
|
|
|
};
|
2007-10-08 23:14:45 +02:00
|
|
|
|
2007-11-22 11:13:08 +01:00
|
|
|
// Partial specialization for one type. Same as std::plus.
|
|
|
|
template<typename _Tp>
|
|
|
|
struct plus<_Tp, _Tp> : public std::binary_function<_Tp, _Tp, _Tp>
|
|
|
|
{
|
2008-06-26 12:45:31 +02:00
|
|
|
typedef __typeof__(*static_cast<_Tp*>(NULL)
|
|
|
|
+ *static_cast<_Tp*>(NULL)) result;
|
2007-10-08 23:14:45 +02:00
|
|
|
|
2007-11-22 11:13:08 +01:00
|
|
|
result
|
|
|
|
operator()(const _Tp& __x, const _Tp& __y) const
|
|
|
|
{ return __x + __y; }
|
|
|
|
};
|
2007-10-08 23:14:45 +02:00
|
|
|
|
|
|
|
|
2007-11-22 11:13:08 +01:00
|
|
|
/** @brief Similar to std::multiplies, but allows two different types. */
|
|
|
|
template<typename _Tp1, typename _Tp2>
|
|
|
|
struct multiplies : public std::binary_function<_Tp1, _Tp2, _Tp1>
|
|
|
|
{
|
2008-06-26 12:45:31 +02:00
|
|
|
typedef __typeof__(*static_cast<_Tp1*>(NULL)
|
|
|
|
* *static_cast<_Tp2*>(NULL)) result;
|
2007-10-08 23:14:45 +02:00
|
|
|
|
2007-11-22 11:13:08 +01:00
|
|
|
result
|
|
|
|
operator()(const _Tp1& __x, const _Tp2& __y) const
|
|
|
|
{ return __x * __y; }
|
|
|
|
};
|
2007-10-08 23:14:45 +02:00
|
|
|
|
2007-11-22 11:13:08 +01:00
|
|
|
// Partial specialization for one type. Same as std::multiplies.
|
|
|
|
template<typename _Tp>
|
|
|
|
struct multiplies<_Tp, _Tp> : public std::binary_function<_Tp, _Tp, _Tp>
|
|
|
|
{
|
2008-06-26 12:45:31 +02:00
|
|
|
typedef __typeof__(*static_cast<_Tp*>(NULL)
|
|
|
|
* *static_cast<_Tp*>(NULL)) result;
|
2007-10-08 23:14:45 +02:00
|
|
|
|
2007-11-22 11:13:08 +01:00
|
|
|
result
|
|
|
|
operator()(const _Tp& __x, const _Tp& __y) const
|
|
|
|
{ return __x * __y; }
|
|
|
|
};
|
2007-10-08 23:14:45 +02:00
|
|
|
|
|
|
|
|
2007-11-22 11:13:08 +01:00
|
|
|
template<typename T, typename _DifferenceTp>
|
2007-09-12 00:32:51 +02:00
|
|
|
class pseudo_sequence;
|
|
|
|
|
2007-11-22 11:13:08 +01:00
|
|
|
/** @brief Iterator associated with __gnu_parallel::pseudo_sequence.
|
|
|
|
* If features the usual random-access iterator functionality.
|
|
|
|
* @param T Sequence value type.
|
|
|
|
* @param difference_type Sequence difference type.
|
|
|
|
*/
|
|
|
|
template<typename T, typename _DifferenceTp>
|
2007-09-12 00:32:51 +02:00
|
|
|
class pseudo_sequence_iterator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef _DifferenceTp difference_type;
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef pseudo_sequence_iterator<T, _DifferenceTp> type;
|
|
|
|
|
|
|
|
const T& val;
|
|
|
|
difference_type pos;
|
|
|
|
|
|
|
|
public:
|
|
|
|
pseudo_sequence_iterator(const T& val, difference_type pos)
|
|
|
|
: val(val), pos(pos) { }
|
|
|
|
|
|
|
|
// Pre-increment operator.
|
|
|
|
type&
|
|
|
|
operator++()
|
|
|
|
{
|
|
|
|
++pos;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Post-increment operator.
|
|
|
|
const type
|
|
|
|
operator++(int)
|
|
|
|
{ return type(pos++); }
|
|
|
|
|
2007-11-22 11:13:08 +01:00
|
|
|
const T&
|
2007-09-12 00:32:51 +02:00
|
|
|
operator*() const
|
|
|
|
{ return val; }
|
|
|
|
|
2007-11-22 11:13:08 +01:00
|
|
|
const T&
|
2007-09-12 00:32:51 +02:00
|
|
|
operator[](difference_type) const
|
|
|
|
{ return val; }
|
|
|
|
|
2007-11-22 11:13:08 +01:00
|
|
|
bool
|
2007-09-12 00:32:51 +02:00
|
|
|
operator==(const type& i2)
|
|
|
|
{ return pos == i2.pos; }
|
|
|
|
|
2007-11-22 11:13:08 +01:00
|
|
|
difference_type
|
2007-09-12 00:32:51 +02:00
|
|
|
operator!=(const type& i2)
|
|
|
|
{ return pos != i2.pos; }
|
|
|
|
|
2007-11-22 11:13:08 +01:00
|
|
|
difference_type
|
2007-09-12 00:32:51 +02:00
|
|
|
operator-(const type& i2)
|
|
|
|
{ return pos - i2.pos; }
|
|
|
|
};
|
|
|
|
|
2007-11-22 11:13:08 +01:00
|
|
|
/** @brief Sequence that conceptually consists of multiple copies of
|
|
|
|
the same element.
|
|
|
|
* The copies are not stored explicitly, of course.
|
|
|
|
* @param T Sequence value type.
|
|
|
|
* @param difference_type Sequence difference type.
|
|
|
|
*/
|
|
|
|
template<typename T, typename _DifferenceTp>
|
2007-09-12 00:32:51 +02:00
|
|
|
class pseudo_sequence
|
|
|
|
{
|
|
|
|
typedef pseudo_sequence<T, _DifferenceTp> type;
|
|
|
|
|
|
|
|
public:
|
|
|
|
typedef _DifferenceTp difference_type;
|
2007-09-14 22:37:25 +02:00
|
|
|
|
2008-02-17 16:46:30 +01:00
|
|
|
// Better case down to uint64, than up to _DifferenceTp.
|
|
|
|
typedef pseudo_sequence_iterator<T, uint64> iterator;
|
2007-09-12 00:32:51 +02:00
|
|
|
|
|
|
|
/** @brief Constructor.
|
2007-11-22 11:13:08 +01:00
|
|
|
* @param val Element of the sequence.
|
|
|
|
* @param count Number of (virtual) copies.
|
|
|
|
*/
|
|
|
|
pseudo_sequence(const T& val, difference_type count)
|
2007-09-12 00:32:51 +02:00
|
|
|
: val(val), count(count) { }
|
|
|
|
|
|
|
|
/** @brief Begin iterator. */
|
|
|
|
iterator
|
|
|
|
begin() const
|
|
|
|
{ return iterator(val, 0); }
|
|
|
|
|
|
|
|
/** @brief End iterator. */
|
|
|
|
iterator
|
|
|
|
end() const
|
|
|
|
{ return iterator(val, count); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
const T& val;
|
|
|
|
difference_type count;
|
|
|
|
};
|
|
|
|
|
2007-11-22 11:13:08 +01:00
|
|
|
/** @brief Functor that does nothing */
|
|
|
|
template<typename _ValueTp>
|
2007-09-12 00:32:51 +02:00
|
|
|
class void_functor
|
|
|
|
{
|
2007-11-22 11:13:08 +01:00
|
|
|
inline void
|
2007-09-12 00:32:51 +02:00
|
|
|
operator()(const _ValueTp& v) const { }
|
|
|
|
};
|
|
|
|
|
2007-11-22 11:13:08 +01:00
|
|
|
/** @brief Compute the median of three referenced elements,
|
|
|
|
according to @c comp.
|
|
|
|
* @param a First iterator.
|
|
|
|
* @param b Second iterator.
|
|
|
|
* @param c Third iterator.
|
|
|
|
* @param comp Comparator.
|
|
|
|
*/
|
|
|
|
template<typename RandomAccessIterator, typename Comparator>
|
2008-01-10 03:07:41 +01:00
|
|
|
RandomAccessIterator
|
2007-11-22 11:13:08 +01:00
|
|
|
median_of_three_iterators(RandomAccessIterator a, RandomAccessIterator b,
|
|
|
|
RandomAccessIterator c, Comparator& comp)
|
2007-09-12 00:32:51 +02:00
|
|
|
{
|
|
|
|
if (comp(*a, *b))
|
|
|
|
if (comp(*b, *c))
|
2007-11-22 11:13:08 +01:00
|
|
|
return b;
|
2007-09-12 00:32:51 +02:00
|
|
|
else
|
2007-11-22 11:13:08 +01:00
|
|
|
if (comp(*a, *c))
|
|
|
|
return c;
|
|
|
|
else
|
|
|
|
return a;
|
2007-09-12 00:32:51 +02:00
|
|
|
else
|
|
|
|
{
|
2007-11-22 11:13:08 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-22 11:13:08 +01:00
|
|
|
// Avoid the use of assert, because we're trying to keep the <cassert>
|
|
|
|
// include out of the mix. (Same as debug mode).
|
|
|
|
inline void
|
|
|
|
__replacement_assert(const char* __file, int __line,
|
|
|
|
const char* __function, const char* __condition)
|
|
|
|
{
|
|
|
|
std::printf("%s:%d: %s: Assertion '%s' failed.\n", __file, __line,
|
|
|
|
__function, __condition);
|
|
|
|
__builtin_abort();
|
|
|
|
}
|
|
|
|
|
2007-09-12 00:32:51 +02:00
|
|
|
#define _GLIBCXX_PARALLEL_ASSERT(_Condition) \
|
2007-11-22 11:13:08 +01:00
|
|
|
do \
|
|
|
|
{ \
|
2008-02-15 23:55:14 +01:00
|
|
|
if (!(_Condition)) \
|
|
|
|
__gnu_parallel::__replacement_assert(__FILE__, __LINE__, \
|
2007-11-22 11:13:08 +01:00
|
|
|
__PRETTY_FUNCTION__, #_Condition); \
|
|
|
|
} while (false)
|
|
|
|
|
2007-09-12 00:32:51 +02:00
|
|
|
} //namespace __gnu_parallel
|
|
|
|
|
2008-07-15 12:06:58 +02:00
|
|
|
#endif /* _GLIBCXX_PARALLEL_BASE_H */
|