1// Boost.Range library
2//
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)
7//
8// For more information, see http://www.boost.org/libs/range/
9//
10
11#ifndef BOOST_RANGE_SIZE_HPP
12#define BOOST_RANGE_SIZE_HPP
13
14#if defined(_MSC_VER)
15# pragma once
16#endif
17
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>
26
27namespace boost
28{
29 namespace range_detail
30 {
31
32 template<class SinglePassRange>
33 inline typename ::boost::enable_if<
34 has_member_size<SinglePassRange>,
35 typename range_size<const SinglePassRange>::type
36 >::type
37 range_calculate_size(const SinglePassRange& rng)
38 {
39 return rng.size();
40 }
41
42 template<class SinglePassRange>
43 inline typename disable_if<
44 has_member_size<SinglePassRange>,
45 typename range_size<const SinglePassRange>::type
46 >::type
47 range_calculate_size(const SinglePassRange& rng)
48 {
49 return std::distance(boost::begin(rng), boost::end(rng));
50 }
51 }
52
53 template<class SinglePassRange>
54 inline typename range_size<const SinglePassRange>::type
55 size(const SinglePassRange& rng)
56 {
57#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) && \
58 !BOOST_WORKAROUND(__GNUC__, < 3) \
59 /**/
60 using namespace range_detail;
61#endif
62 return range_calculate_size(rng);
63 }
64
65} // namespace 'boost'
66
67#endif
68