blob: a337fa3802778f636c47e8fa64423afd69ffced4 [file] [log] [blame]
Jeff Thompsonef2d5a42013-08-22 19:09:24 -07001// Boost string_algo library sequence_traits.hpp header file ---------------------------//
2
3// Copyright Pavol Droba 2002-2003.
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8
9// See http://www.boost.org/ for updates, documentation, and revision history.
10
Jeff Thompson3d613fd2013-10-15 15:39:04 -070011#ifndef NDNBOOST_STRING_SEQUENCE_TRAITS_HPP
12#define NDNBOOST_STRING_SEQUENCE_TRAITS_HPP
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070013
14#include <ndnboost/config.hpp>
15#include <ndnboost/mpl/bool.hpp>
16#include <ndnboost/algorithm/string/yes_no_type.hpp>
17
18/*! \file
19 Traits defined in this header are used by various algorithms to achieve
20 better performance for specific containers.
21 Traits provide fail-safe defaults. If a container supports some of these
22 features, it is possible to specialize the specific trait for this container.
23 For lacking compilers, it is possible of define an override for a specific tester
24 function.
25
26 Due to a language restriction, it is not currently possible to define specializations for
27 stl containers without including the corresponding header. To decrease the overhead
28 needed by this inclusion, user can selectively include a specialization
Jeff Thompson9939dcd2013-10-15 15:12:24 -070029 header for a specific container. They are located in ndnboost/algorithm/string/stl
30 directory. Alternatively she can include ndnboost/algorithm/string/std_collection_traits.hpp
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070031 header which contains specializations for all stl containers.
32*/
33
34namespace ndnboost {
35 namespace algorithm {
36
37// sequence traits -----------------------------------------------//
38
Jeff Thompson3d613fd2013-10-15 15:39:04 -070039#ifdef NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070040
41 //! Native replace tester
42 /*!
43 Declare an override of this tester function with return
44 type ndnboost::string_algo::yes_type for a sequence with this property.
45
46 \return yes_type if the container has basic_string like native replace
47 method.
48 */
49 no_type has_native_replace_tester(...);
50
51 //! Stable iterators tester
52 /*!
53 Declare an override of this tester function with return
54 type ndnboost::string_algo::yes_type for a sequence with this property.
55
56 \return yes_type if the sequence's insert/replace/erase methods do not invalidate
57 existing iterators.
58 */
59 no_type has_stable_iterators_tester(...);
60
61 //! const time insert tester
62 /*!
63 Declare an override of this tester function with return
64 type ndnboost::string_algo::yes_type for a sequence with this property.
65
66 \return yes_type if the sequence's insert method is working in constant time
67 */
68 no_type has_const_time_insert_tester(...);
69
70 //! const time erase tester
71 /*!
72 Declare an override of this tester function with return
73 type ndnboost::string_algo::yes_type for a sequence with this property.
74
75 \return yes_type if the sequence's erase method is working in constant time
76 */
77 no_type has_const_time_erase_tester(...);
78
Jeff Thompson3d613fd2013-10-15 15:39:04 -070079#endif //NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070080
81 //! Native replace trait
82 /*!
83 This trait specifies that the sequence has \c std::string like replace method
84 */
85 template< typename T >
86 class has_native_replace
87 {
88
Jeff Thompson3d613fd2013-10-15 15:39:04 -070089#ifdef NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070090 private:
91 static T* t;
92 public:
Jeff Thompson3d613fd2013-10-15 15:39:04 -070093 NDNBOOST_STATIC_CONSTANT(bool, value=(
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070094 sizeof(has_native_replace_tester(t))==sizeof(yes_type) ) );
Jeff Thompson3d613fd2013-10-15 15:39:04 -070095#else // NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070096 public:
Jeff Thompson3d613fd2013-10-15 15:39:04 -070097# if NDNBOOST_WORKAROUND( __IBMCPP__, <= 600 )
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070098 enum { value = false };
99# else
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700100 NDNBOOST_STATIC_CONSTANT(bool, value=false);
101# endif // NDNBOOST_WORKAROUND( __IBMCPP__, <= 600 )
102#endif // NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700103
104
105 typedef mpl::bool_<has_native_replace<T>::value> type;
106 };
107
108
109 //! Stable iterators trait
110 /*!
111 This trait specifies that the sequence has stable iterators. It means
112 that operations like insert/erase/replace do not invalidate iterators.
113 */
114 template< typename T >
115 class has_stable_iterators
116 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700117#ifdef NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700118 private:
119 static T* t;
120 public:
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700121 NDNBOOST_STATIC_CONSTANT(bool, value=(
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700122 sizeof(has_stable_iterators_tester(t))==sizeof(yes_type) ) );
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700123#else // NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700124 public:
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700125# if NDNBOOST_WORKAROUND( __IBMCPP__, <= 600 )
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700126 enum { value = false };
127# else
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700128 NDNBOOST_STATIC_CONSTANT(bool, value=false);
129# endif // NDNBOOST_WORKAROUND( __IBMCPP__, <= 600 )
130#endif // NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700131
132 typedef mpl::bool_<has_stable_iterators<T>::value> type;
133 };
134
135
136 //! Const time insert trait
137 /*!
138 This trait specifies that the sequence's insert method has
139 constant time complexity.
140 */
141 template< typename T >
142 class has_const_time_insert
143 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700144#ifdef NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700145 private:
146 static T* t;
147 public:
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700148 NDNBOOST_STATIC_CONSTANT(bool, value=(
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700149 sizeof(has_const_time_insert_tester(t))==sizeof(yes_type) ) );
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700150#else // NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700151 public:
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700152# if NDNBOOST_WORKAROUND( __IBMCPP__, <= 600 )
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700153 enum { value = false };
154# else
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700155 NDNBOOST_STATIC_CONSTANT(bool, value=false);
156# endif // NDNBOOST_WORKAROUND( __IBMCPP__, <= 600 )
157#endif // NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700158
159 typedef mpl::bool_<has_const_time_insert<T>::value> type;
160 };
161
162
163 //! Const time erase trait
164 /*!
165 This trait specifies that the sequence's erase method has
166 constant time complexity.
167 */
168 template< typename T >
169 class has_const_time_erase
170 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700171#ifdef NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700172 private:
173 static T* t;
174 public:
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700175 NDNBOOST_STATIC_CONSTANT(bool, value=(
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700176 sizeof(has_const_time_erase_tester(t))==sizeof(yes_type) ) );
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700177#else // NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700178 public:
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700179# if NDNBOOST_WORKAROUND( __IBMCPP__, <= 600 )
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700180 enum { value = false };
181# else
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700182 NDNBOOST_STATIC_CONSTANT(bool, value=false);
183# endif // NDNBOOST_WORKAROUND( __IBMCPP__, <= 600 )
184#endif // NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700185
186 typedef mpl::bool_<has_const_time_erase<T>::value> type;
187 };
188
189 } // namespace algorithm
190} // namespace ndnboost
191
192
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700193#endif // NDNBOOST_STRING_SEQUENCE_TRAITS_HPP