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
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/range/detail/has_member_size.hpp>
23 #include <boost/assert.hpp>
24 #include <boost/cstdint.hpp>
25 #include <boost/utility.hpp>
29 namespace range_detail
32 template<class SinglePassRange>
33 inline typename ::boost::enable_if<
34 has_member_size<SinglePassRange>,
35 typename range_size<const SinglePassRange>::type
37 range_calculate_size(const SinglePassRange& rng)
42 template<class SinglePassRange>
43 inline typename disable_if<
44 has_member_size<SinglePassRange>,
45 typename range_size<const SinglePassRange>::type
47 range_calculate_size(const SinglePassRange& rng)
49 return std::distance(boost::begin(rng), boost::end(rng));
53 template<class SinglePassRange>
54 inline typename range_size<const SinglePassRange>::type
55 size(const SinglePassRange& rng)
57 // Very strange things happen on some compilers that have the range concept
58 // asserts disabled. This preprocessor condition is clearly redundant on a
59 // working compiler but is vital for at least some compilers such as clang 4.2
60 // but only on the Mac!
61 #if BOOST_RANGE_ENABLE_CONCEPT_ASSERT == 1
62 BOOST_RANGE_CONCEPT_ASSERT((boost::SinglePassRangeConcept<SinglePassRange>));
65 #if !BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564)) && \
66 !BOOST_WORKAROUND(__GNUC__, < 3) \
68 using namespace range_detail;
71 return range_calculate_size(rng);
74 } // namespace 'boost'