Chris@16
|
1 // Boost.Range library
|
Chris@16
|
2 //
|
Chris@16
|
3 // Copyright Thorsten Ottosen 2003-2004. Use, modification and
|
Chris@16
|
4 // distribution is subject to the Boost Software License, Version
|
Chris@16
|
5 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
6 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
7 //
|
Chris@16
|
8 // For more information, see http://www.boost.org/libs/range/
|
Chris@16
|
9 //
|
Chris@16
|
10
|
Chris@16
|
11 #ifndef BOOST_RANGE_DETAIL_EMPTY_HPP
|
Chris@16
|
12 #define BOOST_RANGE_DETAIL_EMPTY_HPP
|
Chris@16
|
13
|
Chris@16
|
14 #include <boost/range/detail/common.hpp>
|
Chris@16
|
15
|
Chris@16
|
16 namespace boost
|
Chris@16
|
17 {
|
Chris@16
|
18 namespace range_detail
|
Chris@16
|
19 {
|
Chris@16
|
20 template< typename T >
|
Chris@16
|
21 struct range_empty;
|
Chris@16
|
22
|
Chris@16
|
23 //////////////////////////////////////////////////////////////////////
|
Chris@16
|
24 // default
|
Chris@16
|
25 //////////////////////////////////////////////////////////////////////
|
Chris@16
|
26
|
Chris@16
|
27 template<>
|
Chris@16
|
28 struct range_empty<std_container_>
|
Chris@16
|
29 {
|
Chris@16
|
30 template< typename C >
|
Chris@16
|
31 static bool fun( C& c )
|
Chris@16
|
32 {
|
Chris@16
|
33 return c.empty();
|
Chris@16
|
34 };
|
Chris@16
|
35 };
|
Chris@16
|
36
|
Chris@16
|
37 //////////////////////////////////////////////////////////////////////
|
Chris@16
|
38 // pair
|
Chris@16
|
39 //////////////////////////////////////////////////////////////////////
|
Chris@16
|
40
|
Chris@16
|
41 template<>
|
Chris@16
|
42 struct range_empty<std_pair_>
|
Chris@16
|
43 {
|
Chris@16
|
44 template< typename P >
|
Chris@16
|
45 static bool fun( const P& p )
|
Chris@16
|
46 {
|
Chris@16
|
47 return p.first == p.second;
|
Chris@16
|
48 }
|
Chris@16
|
49 };
|
Chris@16
|
50
|
Chris@16
|
51 //////////////////////////////////////////////////////////////////////
|
Chris@16
|
52 // array
|
Chris@16
|
53 //////////////////////////////////////////////////////////////////////
|
Chris@16
|
54
|
Chris@16
|
55 template<>
|
Chris@16
|
56 struct range_empty<array_>
|
Chris@16
|
57 {
|
Chris@16
|
58 template< typename T, std::size_t sz >
|
Chris@16
|
59 static bool fun( T BOOST_ARRAY_REF[sz] )
|
Chris@16
|
60 {
|
Chris@16
|
61 if( boost_range_array == 0 )
|
Chris@16
|
62 return true;
|
Chris@16
|
63 return false;
|
Chris@16
|
64 }
|
Chris@16
|
65 };
|
Chris@16
|
66
|
Chris@16
|
67 //////////////////////////////////////////////////////////////////////
|
Chris@16
|
68 // string
|
Chris@16
|
69 //////////////////////////////////////////////////////////////////////
|
Chris@16
|
70
|
Chris@16
|
71 template<>
|
Chris@16
|
72 struct range_empty<char_ptr_>
|
Chris@16
|
73 {
|
Chris@16
|
74 static bool fun( const char* s )
|
Chris@16
|
75 {
|
Chris@16
|
76 return s == 0 || s[0] == 0;
|
Chris@16
|
77 }
|
Chris@16
|
78 };
|
Chris@16
|
79
|
Chris@16
|
80 template<>
|
Chris@16
|
81 struct range_empty<const_char_ptr_>
|
Chris@16
|
82 {
|
Chris@16
|
83 static bool fun( const char* s )
|
Chris@16
|
84 {
|
Chris@16
|
85 return s == 0 || s[0] == 0;
|
Chris@16
|
86 }
|
Chris@16
|
87 };
|
Chris@16
|
88
|
Chris@16
|
89 template<>
|
Chris@16
|
90 struct range_empty<wchar_t_ptr_>
|
Chris@16
|
91 {
|
Chris@16
|
92 static bool fun( const wchar_t* s )
|
Chris@16
|
93 {
|
Chris@16
|
94 return s == 0 || s[0] == 0;
|
Chris@16
|
95 }
|
Chris@16
|
96 };
|
Chris@16
|
97
|
Chris@16
|
98 template<>
|
Chris@16
|
99 struct range_empty<const_wchar_t_ptr_>
|
Chris@16
|
100 {
|
Chris@16
|
101 static bool fun( const wchar_t* s )
|
Chris@16
|
102 {
|
Chris@16
|
103 return s == 0 || s[0] == 0;
|
Chris@16
|
104 }
|
Chris@16
|
105 };
|
Chris@16
|
106
|
Chris@16
|
107 } // namespace 'range_detail'
|
Chris@16
|
108
|
Chris@16
|
109
|
Chris@16
|
110 template< typename C >
|
Chris@16
|
111 inline bool
|
Chris@16
|
112 empty( const C& c )
|
Chris@16
|
113 {
|
Chris@16
|
114 return range_detail::range_empty< BOOST_RANGE_DEDUCED_TYPENAME range_detail::range<C>::type >::fun( c );
|
Chris@16
|
115 }
|
Chris@16
|
116
|
Chris@16
|
117 } // namespace 'boost'
|
Chris@16
|
118
|
Chris@16
|
119
|
Chris@16
|
120 #endif
|