sequence_traits.hpp 6.6 KB

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