3 // Copyright Thorsten Ottosen 2003-2004. Use, modification and
4 // distribution is subject to the Boost Software License, Version
5 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
8 // For more information, see http://www.boost.org/libs/range/
11 #ifndef BOOST_RANGE_SIZE_HPP
12 #define BOOST_RANGE_SIZE_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/range/config.hpp>
20 #ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
21 #include <boost/range/detail/size.hpp>
24 #include <boost/range/detail/implementation_help.hpp>
25 #include <boost/range/size_type.hpp>
33 #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
34 namespace range_detail
37 //////////////////////////////////////////////////////////////////////
39 //////////////////////////////////////////////////////////////////////
41 template< typename C >
42 inline BOOST_DEDUCED_TYPENAME C::size_type
43 boost_range_size( const C& c )
48 //////////////////////////////////////////////////////////////////////
50 //////////////////////////////////////////////////////////////////////
52 template< typename Iterator >
53 inline std::size_t boost_range_size( const std::pair<Iterator,Iterator>& p )
55 return std::distance( p.first, p.second );
58 //////////////////////////////////////////////////////////////////////
60 //////////////////////////////////////////////////////////////////////
62 template< typename T, std::size_t sz >
63 inline std::size_t boost_range_size( const T (&array)[sz] )
65 return range_detail::array_size<T,sz>( array );
68 template< typename T, std::size_t sz >
69 inline std::size_t boost_range_size( T (&array)[sz] )
71 return boost::range_detail::array_size<T,sz>( array );
74 //////////////////////////////////////////////////////////////////////
76 //////////////////////////////////////////////////////////////////////
78 inline std::size_t boost_range_size( const char* const& s )
80 return boost::range_detail::str_size( s );
83 inline std::size_t boost_range_size( const wchar_t* const& s )
85 return boost::range_detail::str_size( s );
88 #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
89 } // namespace 'range_detail'
93 inline BOOST_DEDUCED_TYPENAME range_size<T>::type size( const T& r )
95 #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
96 using namespace range_detail;
98 return boost_range_size( r );
102 #if BOOST_WORKAROUND(__MWERKS__, <= 0x3003 ) || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
103 // BCB and CW are not able to overload pointer when class overloads are also available.
104 inline range_size<const char*>::type size( const char* r ) {
105 return range_detail::str_size( r );
107 inline range_size<char*>::type size( char* r ) {
108 return range_detail::str_size( r );
110 inline range_size<const wchar_t*>::type size( const wchar_t* r ) {
111 return range_detail::str_size( r );
113 inline range_size<wchar_t*>::type size( wchar_t* r ) {
114 return range_detail::str_size( r );
119 } // namespace 'boost'
121 #endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING