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>
19 #include <boost/range/begin.hpp>
20 #include <boost/range/end.hpp>
21 #include <boost/range/size_type.hpp>
22 #include <boost/assert.hpp>
26 namespace range_detail
28 template<class SinglePassRange>
29 inline BOOST_DEDUCED_TYPENAME range_size<const SinglePassRange>::type
30 range_calculate_size(const SinglePassRange& rng)
32 BOOST_ASSERT( (boost::end(rng) - boost::begin(rng)) >= 0 &&
33 "reachability invariant broken!" );
34 return boost::end(rng) - boost::begin(rng);
38 template<class SinglePassRange>
39 inline BOOST_DEDUCED_TYPENAME range_size<const SinglePassRange>::type
40 size(const SinglePassRange& rng)
42 #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) && \
43 !BOOST_WORKAROUND(__GNUC__, < 3) \
45 using namespace range_detail;
47 return range_calculate_size(rng);
50 } // namespace 'boost'