Files
boost_range/include/boost/range/size.hpp

124 lines
3.6 KiB
C++
Raw Normal View History

2004-06-29 02:50:07 +00:00
// Boost.Range library
//
// Copyright Thorsten Ottosen 2003-2004. Use, modification and
// distribution is subject to the Boost Software License, Version
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// For more information, see http://www.boost.org/libs/range/
//
#ifndef BOOST_RANGE_SIZE_HPP
#define BOOST_RANGE_SIZE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif
#include <boost/range/config.hpp>
#ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
#include <boost/range/detail/size.hpp>
#else
#include <boost/range/detail/implementation_help.hpp>
2004-08-10 16:09:30 +00:00
#include <boost/range/size_type.hpp>
2004-06-29 02:50:07 +00:00
#include <cstddef>
#include <iterator>
#include <utility>
2004-08-10 16:09:30 +00:00
namespace boost
{
2005-03-24 11:23:04 +00:00
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
2004-08-16 22:07:07 +00:00
namespace range_detail
2004-06-29 02:50:07 +00:00
{
2005-03-24 11:23:04 +00:00
#endif
2004-06-29 02:50:07 +00:00
//////////////////////////////////////////////////////////////////////
2004-08-10 16:09:30 +00:00
// primary template
2004-06-29 02:50:07 +00:00
//////////////////////////////////////////////////////////////////////
template< typename C >
2004-08-20 19:26:34 +00:00
inline BOOST_DEDUCED_TYPENAME C::size_type
2005-03-24 11:23:04 +00:00
boost_range_size( const C& c )
2004-06-29 02:50:07 +00:00
{
return c.size();
}
//////////////////////////////////////////////////////////////////////
// pair
//////////////////////////////////////////////////////////////////////
template< typename Iterator >
2005-03-24 11:23:04 +00:00
inline std::size_t boost_range_size( const std::pair<Iterator,Iterator>& p )
2004-06-29 02:50:07 +00:00
{
return std::distance( p.first, p.second );
}
//////////////////////////////////////////////////////////////////////
// array
//////////////////////////////////////////////////////////////////////
template< typename T, std::size_t sz >
2005-03-24 11:23:04 +00:00
inline std::size_t boost_range_size( const T (&array)[sz] )
2004-06-29 02:50:07 +00:00
{
return range_detail::array_size<T,sz>( array );
2004-06-29 02:50:07 +00:00
}
template< typename T, std::size_t sz >
2005-03-24 11:23:04 +00:00
inline std::size_t boost_range_size( T (&array)[sz] )
2004-06-29 02:50:07 +00:00
{
2004-07-27 13:37:44 +00:00
return boost::range_detail::array_size<T,sz>( array );
2004-06-29 02:50:07 +00:00
}
//////////////////////////////////////////////////////////////////////
// string
//////////////////////////////////////////////////////////////////////
2005-03-24 11:23:04 +00:00
inline std::size_t boost_range_size( const char* const& s )
2004-06-29 02:50:07 +00:00
{
return boost::range_detail::str_size( s );
2004-06-29 02:50:07 +00:00
}
2005-03-24 11:23:04 +00:00
inline std::size_t boost_range_size( const wchar_t* const& s )
2004-06-29 02:50:07 +00:00
{
return boost::range_detail::str_size( s );
2004-06-29 02:50:07 +00:00
}
2005-03-24 11:23:04 +00:00
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
2004-08-20 19:26:34 +00:00
} // namespace 'range_detail'
2005-03-24 11:23:04 +00:00
#endif
2004-06-29 02:50:07 +00:00
2004-08-10 16:09:30 +00:00
template< class T >
2005-03-24 11:23:04 +00:00
inline BOOST_DEDUCED_TYPENAME range_size<T>::type size( const T& r )
2004-08-10 16:09:30 +00:00
{
2005-03-24 11:23:04 +00:00
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
using namespace range_detail;
#endif
return boost_range_size( r );
2004-08-10 16:09:30 +00:00
}
2004-06-29 02:50:07 +00:00
2004-09-16 18:27:51 +00:00
2005-01-05 18:19:31 +00:00
#if BOOST_WORKAROUND(__MWERKS__, <= 0x3003 ) || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
2004-09-26 13:13:04 +00:00
// BCB and CW are not able to overload pointer when class overloads are also available.
2005-03-24 11:23:04 +00:00
inline range_size<const char*>::type size( const char* r ) {
2004-09-02 17:32:58 +00:00
return range_detail::str_size( r );
}
2005-03-24 11:23:04 +00:00
inline range_size<char*>::type size( char* r ) {
2004-09-26 12:15:12 +00:00
return range_detail::str_size( r );
}
2005-03-24 11:23:04 +00:00
inline range_size<const wchar_t*>::type size( const wchar_t* r ) {
2004-09-26 12:15:12 +00:00
return range_detail::str_size( r );
}
2005-03-24 11:23:04 +00:00
inline range_size<wchar_t*>::type size( wchar_t* r ) {
2004-09-02 17:32:58 +00:00
return range_detail::str_size( r );
}
#endif
2004-09-16 18:27:51 +00:00
2004-09-02 17:32:58 +00:00
2004-06-29 02:50:07 +00:00
} // namespace 'boost'
#endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING
#endif