* include/bits/stl_algo.h (shuffle): Add, per D3056.
(random_shuffle): Fix signature in C++0x mode.
(lower_bound, __lg): Move...
* include/bits/stl_algobase.h: ... here.
* include/bits/algorithmfwd.h: Adjust.
* include/parallel/algorithmfwd.h: Likewise.
* include/parallel/algo.h: Likewise.
* include/bits/hashtable_policy.h (__lower_bound): Remove,
adjust callers.
* include/tr1/hashtable_policy.h (__lower_bound): Likewise.
* include/bits/random.tcc (__detail::__transform): Add,
adjust std::transform callers; don't include <algorithm>.
* testsuite/25_algorithms/shuffle/1.cc: Add.
* testsuite/25_algorithms/shuffle/requirements/
explicit_instantiation/2.cc: Likewise.
* testsuite/25_algorithms/shuffle/requirements/
explicit_instantiation/pod.cc: Likewise.
* include/bits/random.h: Add comments.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@157564
138bc75d-0d04-0410-961f-
82ee72b054a4
+2010-03-19 Paolo Carlini <paolo.carlini@oracle.com>
+
+ * include/bits/stl_algo.h (shuffle): Add, per D3056.
+ (random_shuffle): Fix signature in C++0x mode.
+ (lower_bound, __lg): Move...
+ * include/bits/stl_algobase.h: ... here.
+ * include/bits/algorithmfwd.h: Adjust.
+ * include/parallel/algorithmfwd.h: Likewise.
+ * include/parallel/algo.h: Likewise.
+ * include/bits/hashtable_policy.h (__lower_bound): Remove,
+ adjust callers.
+ * include/tr1/hashtable_policy.h (__lower_bound): Likewise.
+ * include/bits/random.tcc (__detail::__transform): Add,
+ adjust std::transform callers; don't include <algorithm>.
+ * testsuite/25_algorithms/shuffle/1.cc: Add.
+ * testsuite/25_algorithms/shuffle/requirements/
+ explicit_instantiation/2.cc: Likewise.
+ * testsuite/25_algorithms/shuffle/requirements/
+ explicit_instantiation/pod.cc: Likewise.
+
+ * include/bits/random.h: Add comments.
+
2010-03-17 Jonathan Wakely <jwakely.gcc@gmail.com>
* doc/xml/manual/debug_mode.xml: Correct debug headers.
#if defined(__GXX_EXPERIMENTAL_CXX0X__) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
template<typename _RAIter, typename _UGenerator>
void
- shuffle(_RAIter, _RAIter, _UGenerator&);
+ shuffle(_RAIter, _RAIter, _UGenerator&&);
#endif
template<typename _RAIter>
{ return _M_param.t(); }
/**
+ * @brief Generating functions.
+ */
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng)
+ { return this->operator()(__urng, this->param()); }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
+ /**
* @brief Return true if two binomial distributions have
* the same parameters and the sequences that would
* be generated are equal.
{ return __d1.param() == __d2.param(); }
#endif
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng)
- { return this->operator()(__urng, this->param()); }
-
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng,
- const param_type& __p);
-
/**
* @brief Return true if two binomial distributions have
* the same parameters and the sequences that would
{ return __a * __x + __c; }
};
- template<typename _InputIterator, typename _OutputIterator,
- typename _UnaryOperation>
- _OutputIterator
- __transform(_InputIterator __first, _InputIterator __last,
- _OutputIterator __result, _UnaryOperation __unary_op)
- {
- for (; __first != __last; ++__first, ++__result)
- *__result = __unary_op(*__first);
- return __result;
- }
+ template<typename _InputIterator, typename _OutputIterator,
+ typename _UnaryOperation>
+ _OutputIterator
+ __transform(_InputIterator __first, _InputIterator __last,
+ _OutputIterator __result, _UnaryOperation __unary_op)
+ {
+ for (; __first != __last; ++__first, ++__result)
+ *__result = __unary_op(*__first);
+ return __result;
+ }
} // namespace __detail
// lower_bound moved to stl_algobase.h
/**
- * @brief Finds the first position in which @a val could be inserted
- * without changing the ordering.
- * @ingroup binary_search_algorithms
- * @param first An iterator.
- * @param last Another iterator.
- * @param val The search term.
- * @param comp A functor to use for comparisons.
- * @return An iterator pointing to the first element <em>not less
- * than</em> @a val, or end() if every element is less
- * than @a val.
- * @ingroup binary_search_algorithms
- *
- * The comparison function should have the same effects on ordering as
- * the function used for the initial sort.
- */
- template<typename _ForwardIterator, typename _Tp, typename _Compare>
- _ForwardIterator
- lower_bound(_ForwardIterator __first, _ForwardIterator __last,
- const _Tp& __val, _Compare __comp)
- {
- typedef typename iterator_traits<_ForwardIterator>::value_type
- _ValueType;
- typedef typename iterator_traits<_ForwardIterator>::difference_type
- _DistanceType;
-
- // concept requirements
- __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
- __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
- _ValueType, _Tp>)
- __glibcxx_requires_partitioned_lower_pred(__first, __last,
- __val, __comp);
-
- _DistanceType __len = std::distance(__first, __last);
- _DistanceType __half;
- _ForwardIterator __middle;
-
- while (__len > 0)
- {
- __half = __len >> 1;
- __middle = __first;
- std::advance(__middle, __half);
- if (__comp(*__middle, __val))
- {
- __first = __middle;
- ++__first;
- __len = __len - __half - 1;
- }
- else
- __len = __half;
- }
- return __first;
- }
-
- /**
* @brief Finds the last position in which @a val could be inserted
* without changing the ordering.
* @ingroup binary_search_algorithms
typename _UniformRandomNumberGenerator>
void
shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last,
- _UniformRandomNumberGenerator& __g)
+ _UniformRandomNumberGenerator&& __g)
{
// concept requirements
__glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
return __first;
}
+ /**
+ * @brief Finds the first position in which @a val could be inserted
+ * without changing the ordering.
+ * @ingroup binary_search_algorithms
+ * @param first An iterator.
+ * @param last Another iterator.
+ * @param val The search term.
+ * @param comp A functor to use for comparisons.
+ * @return An iterator pointing to the first element <em>not less
+ * than</em> @a val, or end() if every element is less
+ * than @a val.
+ * @ingroup binary_search_algorithms
+ *
+ * The comparison function should have the same effects on ordering as
+ * the function used for the initial sort.
+ */
+ template<typename _ForwardIterator, typename _Tp, typename _Compare>
+ _ForwardIterator
+ lower_bound(_ForwardIterator __first, _ForwardIterator __last,
+ const _Tp& __val, _Compare __comp)
+ {
+ typedef typename iterator_traits<_ForwardIterator>::value_type
+ _ValueType;
+ typedef typename iterator_traits<_ForwardIterator>::difference_type
+ _DistanceType;
+
+ // concept requirements
+ __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
+ __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
+ _ValueType, _Tp>)
+ __glibcxx_requires_partitioned_lower_pred(__first, __last,
+ __val, __comp);
+
+ _DistanceType __len = std::distance(__first, __last);
+ _DistanceType __half;
+ _ForwardIterator __middle;
+
+ while (__len > 0)
+ {
+ __half = __len >> 1;
+ __middle = __first;
+ std::advance(__middle, __half);
+ if (__comp(*__middle, __val))
+ {
+ __first = __middle;
+ ++__first;
+ __len = __len - __half - 1;
+ }
+ else
+ __len = __half;
+ }
+ return __first;
+ }
+
/// This is a helper function for the sort routines and for random.tcc.
// Precondition: __n > 0.
template<typename _Size>
typedef value_type* iterator_type;
typedef std::mt19937_64 ugenerator_type;
- template void shuffle(iterator_type, iterator_type, ugenerator_type&);
+ template void shuffle(iterator_type, iterator_type, ugenerator_type&&);
}
typedef value_type* iterator_type;
typedef std::mt19937_64 ugenerator_type;
- template void shuffle(iterator_type, iterator_type, ugenerator_type&);
+ template void shuffle(iterator_type, iterator_type, ugenerator_type&&);
}