Long time ago I inquired if it would be a good idea to provide STL extensions in boost that are not implemented by all STL's. IIRC David A responded that boost/compatibility was intended for this.
So I finally started with implementing is_sorted and iota. Also as David Abrahams suggested, I've put them in the boost namespace (but they reuse the implementation in the std namespace if available). The definitions are also located in a file with the same name (except for the attached .hpp extension) as defined by the SGI/STL. I propose to put these in the boost/compatibility directory. Opinions ?
#ifndef boost_compatibility_config_hpp #define boost_compatibility_config_hpp #if (__GNUC__ >= 3) && ( __GNUC_MINOR__ >= 1 ) #define BOOST_NO_IS_SORTED #define BOOST_NO_IOTA #endif #if (__IBMCPP__) #define BOOST_NO_IS_SORTED #define BOOST_NO_IOTA #endif #if defined(__ICC) #define BOOST_NO_IS_SORTED #endif #endif // boost_compatibility_config_hpp
#ifndef boost_compatibility_algorithm_hpp #define boost_compatibility_algorithm_hpp #include <boost/compatibility/config.hpp> #if ! defined( BOOST_NO_IS_SORTED ) #include <algorithm> #endif namespace boost { #if defined( BOOST_NO_IS_SORTED ) template <class ForwardIterator> bool is_sorted(ForwardIterator begin, ForwardIterator end) { if (begin == end) return true; ForwardIterator next = begin ; ++next ; for ( ; next != end; ++begin , ++next) { if (*next < *begin) return false; } return true; } template <class ForwardIterator, class StrictWeakOrdering> bool is_sorted(ForwardIterator begin, ForwardIterator end, StrictWeakOrdering comp) { if (begin == end) return true; ForwardIterator next = begin ; ++next ; for ( ; next != end ; ++begin, ++next) { if ( comp(*next, *first) ) return false; } return true; } #else template <class ForwardIterator> inline bool is_sorted(ForwardIterator begin, ForwardIterator end) { return std::is_sorted( begin, end ) ; } template <class ForwardIterator, class StrictWeakOrdering> inline bool is_sorted(ForwardIterator begin, ForwardIterator end, StrictWeakOrdering comp) { return std::is_sorted( begin, end, comp ) ; } #endif // NO_IS_SORTED } // namespace boost #endif // boost_compatibility_algorithm_hpp
#ifndef boost_compatibility_numeric_hpp #define boost_compatibility_numeric_hpp #include <boost/compatibility/config.hpp> #if ! defined( BOOST_NO_IOTA ) #include <numeric> #endif namespace boost { #if defined( BOOST_NO_IOTA ) template <class ForwardIterator, class ValueType > void iota(ForwardIterator begin, ForwardIterator end, ValueType value) { while ( begin != end ) { *begin = value ; ++begin ; ++value ; } } #else template <class ForwardIterator, class ValueType > inline void iota(ForwardIterator begin, ForwardIterator end, ValueType value) { std::iota( begin, end, value ) ; } #endif // NO_IOTA } // namespace boost #endif // boost_compatibility_numeric_hpp
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost