Click here to Skip to main content
15,896,201 members
Articles / Programming Languages / C++

Napkin

Rate me:
Please Sign up or sign in to vote.
4.38/5 (4 votes)
12 Mar 20063 min read 39.1K   66   11  
A simple logging library using generic object to streams
#pragma once

/// \file stable_sort.hpp
/// tomato::stable_sort works around CRT.
/// std::stable_sort triggers the buffered merge-sort that seems to require CRT.

#include <algorithm>
#include <functional>
#include <boost/iterator/iterator_traits.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/value_type.hpp>

namespace pstade { namespace tomato {


/// \cond OUTPUT_DETAIL
namespace stable_sort_detail {


	template< class RandomAccessIter, class Predicate > inline
	void insertion_sort(RandomAccessIter first, RandomAccessIter last, Predicate pred)
	{
	#if defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)
		std::__insertion_sort(first, last, pred);
	#else
		std::_Insertion_sort(first, last, pred);
	#endif
	}


} // namespace stable_sort_detail
/// \endcond


// iterator interface
template< class RandomAccessIter, class Predicate > inline
void stable_sort(RandomAccessIter first, RandomAccessIter last, Predicate pred)
{
	stable_sort_detail::insertion_sort(first, last, pred);
}

// range interface
template< class RandomAccessRange, class Predicate > inline
void stable_sort(RandomAccessRange& rng, Predicate pred)
{
	tomato::stable_sort(boost::begin(rng), boost::end(rng), pred);
}

// const-range interface
template< class RandomAccessRange, class Predicate > inline
void stable_sort(RandomAccessRange const& rng, Predicate pred)
{
	tomato::stable_sort(boost::begin(rng), boost::end(rng), pred);
}

// default less predicate

// iterator interface
template< class RandomAccessIter > inline
void stable_sort(RandomAccessIter first, RandomAccessIter last)
{
	typedef typename boost::iterator_value<RandomAccessIter>::type value_t;

	tomato::stable_sort(first, last, std::less<value_t>());
}

// range interface
template< class RandomAccessRange > inline
void stable_sort(RandomAccessRange& rng)
{
	typedef typename boost::range_value<RandomAccessRange>::type value_t;

	tomato::stable_sort(boost::begin(rng), boost::end(rng), std::less<value_t>());
}

// const-range interface
template< class RandomAccessRange > inline
void stable_sort(RandomAccessRange const& rng)
{
	typedef typename boost::range_value<RandomAccessRange>::type value_t;

	tomato::stable_sort(boost::begin(rng), boost::end(rng), std::less<value_t>());
}


} } // namespace pstade::tomato

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Japan Japan
I am worried about my poor English...

Comments and Discussions