1 | // Boost string_algo library sequence_traits.hpp header file ---------------------------//
|
---|
2 |
|
---|
3 | // Copyright Pavol Droba 2002-2003. 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 | // See http://www.boost.org for updates, documentation, and revision history.
|
---|
9 |
|
---|
10 | #ifndef BOOST_STRING_SEQUENCE_TRAITS_HPP
|
---|
11 | #define BOOST_STRING_SEQUENCE_TRAITS_HPP
|
---|
12 |
|
---|
13 | #include <boost/config.hpp>
|
---|
14 | #include <boost/mpl/bool.hpp>
|
---|
15 | #include <boost/algorithm/string/yes_no_type.hpp>
|
---|
16 |
|
---|
17 | /*! \file
|
---|
18 | Traits defined in this header are used by various algorithms to achieve
|
---|
19 | better performance for specific containers.
|
---|
20 | Traits provide fail-safe defaults. If a container supports some of these
|
---|
21 | features, it is possible to specialize the specific trait for this container.
|
---|
22 | For lacking compilers, it is possible of define an override for a specific tester
|
---|
23 | function.
|
---|
24 |
|
---|
25 | Due to a language restriction, it is not currently possible to define specializations for
|
---|
26 | stl containers without including the corresponding header. To decrease the overhead
|
---|
27 | needed by this inclusion, user can selectively include a specialization
|
---|
28 | header for a specific container. They are located in boost/algorithm/string/stl
|
---|
29 | directory. Alternatively she can include boost/algorithm/string/std_collection_traits.hpp
|
---|
30 | header which contains specializations for all stl containers.
|
---|
31 | */
|
---|
32 |
|
---|
33 | namespace boost {
|
---|
34 | namespace algorithm {
|
---|
35 |
|
---|
36 | // sequence traits -----------------------------------------------//
|
---|
37 |
|
---|
38 | #ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
---|
39 |
|
---|
40 | //! Native replace tester
|
---|
41 | /*!
|
---|
42 | Declare an override of this tester function with return
|
---|
43 | type boost::string_algo::yes_type for a sequence with this property.
|
---|
44 |
|
---|
45 | \return yes_type if the container has basic_string like native replace
|
---|
46 | method.
|
---|
47 | */
|
---|
48 | no_type has_native_replace_tester(...);
|
---|
49 |
|
---|
50 | //! Stable iterators tester
|
---|
51 | /*!
|
---|
52 | Declare an override of this tester function with return
|
---|
53 | type boost::string_algo::yes_type for a sequence with this property.
|
---|
54 |
|
---|
55 | \return yes_type if the sequence's insert/replace/erase methods do not invalidate
|
---|
56 | existing iterators.
|
---|
57 | */
|
---|
58 | no_type has_stable_iterators_tester(...);
|
---|
59 |
|
---|
60 | //! const time insert tester
|
---|
61 | /*!
|
---|
62 | Declare an override of this tester function with return
|
---|
63 | type boost::string_algo::yes_type for a sequence with this property.
|
---|
64 |
|
---|
65 | \return yes_type if the sequence's insert method is working in constant time
|
---|
66 | */
|
---|
67 | no_type has_const_time_insert_tester(...);
|
---|
68 |
|
---|
69 | //! const time erase tester
|
---|
70 | /*!
|
---|
71 | Declare an override of this tester function with return
|
---|
72 | type boost::string_algo::yes_type for a sequence with this property.
|
---|
73 |
|
---|
74 | \return yes_type if the sequence's erase method is working in constant time
|
---|
75 | */
|
---|
76 | no_type has_const_time_erase_tester(...);
|
---|
77 |
|
---|
78 | #endif //BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
---|
79 |
|
---|
80 | //! Native replace trait
|
---|
81 | /*!
|
---|
82 | This trait specifies that the sequence has \c std::string like replace method
|
---|
83 | */
|
---|
84 | template< typename T >
|
---|
85 | class has_native_replace
|
---|
86 | {
|
---|
87 |
|
---|
88 | #ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
---|
89 | private:
|
---|
90 | static T* t;
|
---|
91 | public:
|
---|
92 | BOOST_STATIC_CONSTANT(bool, value=(
|
---|
93 | sizeof(has_native_replace_tester(t))==sizeof(yes_type) ) );
|
---|
94 | #else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
---|
95 | public:
|
---|
96 | # if BOOST_WORKAROUND( __IBMCPP__, <= 600 )
|
---|
97 | enum { value = false };
|
---|
98 | # else
|
---|
99 | BOOST_STATIC_CONSTANT(bool, value=false);
|
---|
100 | # endif // BOOST_WORKAROUND( __IBMCPP__, <= 600 )
|
---|
101 | #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
---|
102 |
|
---|
103 |
|
---|
104 | typedef mpl::bool_<has_native_replace<T>::value> type;
|
---|
105 | };
|
---|
106 |
|
---|
107 |
|
---|
108 | //! Stable iterators trait
|
---|
109 | /*!
|
---|
110 | This trait specifies that the sequence has stable iterators. It means
|
---|
111 | that operations like insert/erase/replace do not invalidate iterators.
|
---|
112 | */
|
---|
113 | template< typename T >
|
---|
114 | class has_stable_iterators
|
---|
115 | {
|
---|
116 | #ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
---|
117 | private:
|
---|
118 | static T* t;
|
---|
119 | public:
|
---|
120 | BOOST_STATIC_CONSTANT(bool, value=(
|
---|
121 | sizeof(has_stable_iterators_tester(t))==sizeof(yes_type) ) );
|
---|
122 | #else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
---|
123 | public:
|
---|
124 | # if BOOST_WORKAROUND( __IBMCPP__, <= 600 )
|
---|
125 | enum { value = false };
|
---|
126 | # else
|
---|
127 | BOOST_STATIC_CONSTANT(bool, value=false);
|
---|
128 | # endif // BOOST_WORKAROUND( __IBMCPP__, <= 600 )
|
---|
129 | #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
---|
130 |
|
---|
131 | typedef mpl::bool_<has_stable_iterators<T>::value> type;
|
---|
132 | };
|
---|
133 |
|
---|
134 |
|
---|
135 | //! Const time insert trait
|
---|
136 | /*!
|
---|
137 | This trait specifies that the sequence's insert method has
|
---|
138 | constant time complexity.
|
---|
139 | */
|
---|
140 | template< typename T >
|
---|
141 | class has_const_time_insert
|
---|
142 | {
|
---|
143 | #ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
---|
144 | private:
|
---|
145 | static T* t;
|
---|
146 | public:
|
---|
147 | BOOST_STATIC_CONSTANT(bool, value=(
|
---|
148 | sizeof(has_const_time_insert_tester(t))==sizeof(yes_type) ) );
|
---|
149 | #else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
---|
150 | public:
|
---|
151 | # if BOOST_WORKAROUND( __IBMCPP__, <= 600 )
|
---|
152 | enum { value = false };
|
---|
153 | # else
|
---|
154 | BOOST_STATIC_CONSTANT(bool, value=false);
|
---|
155 | # endif // BOOST_WORKAROUND( __IBMCPP__, <= 600 )
|
---|
156 | #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
---|
157 |
|
---|
158 | typedef mpl::bool_<has_const_time_insert<T>::value> type;
|
---|
159 | };
|
---|
160 |
|
---|
161 |
|
---|
162 | //! Const time erase trait
|
---|
163 | /*!
|
---|
164 | This trait specifies that the sequence's erase method has
|
---|
165 | constant time complexity.
|
---|
166 | */
|
---|
167 | template< typename T >
|
---|
168 | class has_const_time_erase
|
---|
169 | {
|
---|
170 | #ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
---|
171 | private:
|
---|
172 | static T* t;
|
---|
173 | public:
|
---|
174 | BOOST_STATIC_CONSTANT(bool, value=(
|
---|
175 | sizeof(has_const_time_erase_tester(t))==sizeof(yes_type) ) );
|
---|
176 | #else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
---|
177 | public:
|
---|
178 | # if BOOST_WORKAROUND( __IBMCPP__, <= 600 )
|
---|
179 | enum { value = false };
|
---|
180 | # else
|
---|
181 | BOOST_STATIC_CONSTANT(bool, value=false);
|
---|
182 | # endif // BOOST_WORKAROUND( __IBMCPP__, <= 600 )
|
---|
183 | #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
---|
184 |
|
---|
185 | typedef mpl::bool_<has_const_time_erase<T>::value> type;
|
---|
186 | };
|
---|
187 |
|
---|
188 | } // namespace algorithm
|
---|
189 | } // namespace boost
|
---|
190 |
|
---|
191 |
|
---|
192 | #endif // BOOST_STRING_SEQUENCE_TRAITS_HPP
|
---|