|
Boost : |
From: Toon Knapen (toon.knapen_at_[hidden])
Date: 2002-10-01 03:06:42
I've been using my own std::is_sorted, std::iota etc. on compilers/stl's that
do not provide these extensions (snippet below). OTOH, I've seen that
boost/detail/algorithm does the same thing (but here all these are defined in
the boost namespace, not the std namespace).
Now I think it would be interesting to provide these extensions for all stl's
that do not include these to improve portabilitity of C++ programs. Should
boost/detail/algorithm.hpp be used for this (but in that case the header
should directly be in the boost includes and not in a 'detail' subdirectory)
or would it be better to define these in the std namespace ?
#if defined(__ICC)
#define FEMTOWN_NO_IS_SORTED
#endif
#if (__GNUC__ >= 3) && ( __GNUC_MINOR__ >= 1 )
#define FEMTOWN_NO_IS_SORTED
#define FEMTOWN_NO_IOTA
#endif
#if (__IBMCPP__)
#define FEMTOWN_NO_IS_SORTED
#define FEMTOWN_NO_IOTA
#endif
namespace std {
#if defined( FEMTOWN_NO_IS_SORTED )
// copied from g++-v3 in gcc-2.95.3
template <class _ForwardIter>
bool is_sorted(_ForwardIter __first, _ForwardIter __last)
{
if (__first == __last)
return true;
_ForwardIter __next = __first;
for (++__next; __next != __last; __first = __next, ++__next) {
if (*__next < *__first)
return false;
}
return true;
}
template <class _ForwardIter, class _StrictWeakOrdering>
bool is_sorted(_ForwardIter __first, _ForwardIter __last,
_StrictWeakOrdering __comp)
{
if (__first == __last)
return true;
_ForwardIter __next = __first;
for (++__next; __next != __last; __first = __next, ++__next) {
if (__comp(*__next, *__first))
return false;
}
return true;
}
#endif // NO_IS_SORTED
#if defined( FEMTOWN_NO_IOTA )
// copied from gcc-3.0.4
template <class _ForwardIter, class _Tp>
void
iota(_ForwardIter __first, _ForwardIter __last, _Tp __value)
{
while (__first != __last)
*__first++ = __value++;
}
#endif // NO_IOTA
} // namespace std
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk