]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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_DETAIL_EMPTY_HPP | |
12 | #define BOOST_RANGE_DETAIL_EMPTY_HPP | |
13 | ||
14 | #include <boost/range/detail/common.hpp> | |
15 | ||
16 | namespace boost | |
17 | { | |
18 | namespace range_detail | |
19 | { | |
20 | template< typename T > | |
21 | struct range_empty; | |
22 | ||
23 | ////////////////////////////////////////////////////////////////////// | |
24 | // default | |
25 | ////////////////////////////////////////////////////////////////////// | |
26 | ||
27 | template<> | |
28 | struct range_empty<std_container_> | |
29 | { | |
30 | template< typename C > | |
31 | static bool fun( C& c ) | |
32 | { | |
33 | return c.empty(); | |
34 | }; | |
35 | }; | |
36 | ||
37 | ////////////////////////////////////////////////////////////////////// | |
38 | // pair | |
39 | ////////////////////////////////////////////////////////////////////// | |
40 | ||
41 | template<> | |
42 | struct range_empty<std_pair_> | |
43 | { | |
44 | template< typename P > | |
45 | static bool fun( const P& p ) | |
46 | { | |
47 | return p.first == p.second; | |
48 | } | |
49 | }; | |
50 | ||
51 | ////////////////////////////////////////////////////////////////////// | |
52 | // array | |
53 | ////////////////////////////////////////////////////////////////////// | |
54 | ||
55 | template<> | |
56 | struct range_empty<array_> | |
57 | { | |
58 | template< typename T, std::size_t sz > | |
59 | static bool fun( T BOOST_ARRAY_REF[sz] ) | |
60 | { | |
61 | if( boost_range_array == 0 ) | |
62 | return true; | |
63 | return false; | |
64 | } | |
65 | }; | |
66 | ||
67 | ////////////////////////////////////////////////////////////////////// | |
68 | // string | |
69 | ////////////////////////////////////////////////////////////////////// | |
70 | ||
71 | template<> | |
72 | struct range_empty<char_ptr_> | |
73 | { | |
74 | static bool fun( const char* s ) | |
75 | { | |
76 | return s == 0 || s[0] == 0; | |
77 | } | |
78 | }; | |
79 | ||
80 | template<> | |
81 | struct range_empty<const_char_ptr_> | |
82 | { | |
83 | static bool fun( const char* s ) | |
84 | { | |
85 | return s == 0 || s[0] == 0; | |
86 | } | |
87 | }; | |
88 | ||
89 | template<> | |
90 | struct range_empty<wchar_t_ptr_> | |
91 | { | |
92 | static bool fun( const wchar_t* s ) | |
93 | { | |
94 | return s == 0 || s[0] == 0; | |
95 | } | |
96 | }; | |
97 | ||
98 | template<> | |
99 | struct range_empty<const_wchar_t_ptr_> | |
100 | { | |
101 | static bool fun( const wchar_t* s ) | |
102 | { | |
103 | return s == 0 || s[0] == 0; | |
104 | } | |
105 | }; | |
106 | ||
107 | } // namespace 'range_detail' | |
108 | ||
109 | ||
110 | template< typename C > | |
111 | inline bool | |
112 | empty( const C& c ) | |
113 | { | |
114 | return range_detail::range_empty< BOOST_RANGE_DEDUCED_TYPENAME range_detail::range<C>::type >::fun( c ); | |
115 | } | |
116 | ||
117 | } // namespace 'boost' | |
118 | ||
119 | ||
120 | #endif |