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 
27 namespace pdalboost
28 {
29     namespace range_detail
30     {
31 
32         template<class SinglePassRange>
33         inline typename ::pdalboost::enable_if<
34             has_member_size<SinglePassRange>,
35             typename range_size<const SinglePassRange>::type
36         >::type
range_calculate_size(const SinglePassRange & rng)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
range_calculate_size(const SinglePassRange & rng)47         range_calculate_size(const SinglePassRange& rng)
48         {
49             return std::distance(pdalboost::begin(rng), pdalboost::end(rng));
50         }
51     }
52 
53     template<class SinglePassRange>
54     inline typename range_size<const SinglePassRange>::type
size(const SinglePassRange & rng)55     size(const SinglePassRange& rng)
56     {
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((pdalboost::SinglePassRangeConcept<SinglePassRange>));
63 #endif
64 
65 #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) && \
66     !BOOST_WORKAROUND(__GNUC__, < 3) \
67     /**/
68         using namespace range_detail;
69 #endif
70 
71         return range_calculate_size(rng);
72     }
73 
74 } // namespace 'boost'
75 
76 #endif
77