util.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // Boost string_algo library util.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_UTIL_DETAIL_HPP
  9. #define BOOST_STRING_UTIL_DETAIL_HPP
  10. #include <boost/algorithm/string/config.hpp>
  11. #include <functional>
  12. #include <boost/range/iterator_range_core.hpp>
  13. namespace boost {
  14. namespace algorithm {
  15. namespace detail {
  16. // empty container -----------------------------------------------//
  17. // empty_container
  18. /*
  19. This class represents always empty container,
  20. containing elements of type CharT.
  21. It is supposed to be used in a const version only
  22. */
  23. template< typename CharT >
  24. struct empty_container
  25. {
  26. typedef empty_container<CharT> type;
  27. typedef CharT value_type;
  28. typedef std::size_t size_type;
  29. typedef std::ptrdiff_t difference_type;
  30. typedef const value_type& reference;
  31. typedef const value_type& const_reference;
  32. typedef const value_type* iterator;
  33. typedef const value_type* const_iterator;
  34. // Operations
  35. const_iterator begin() const
  36. {
  37. return reinterpret_cast<const_iterator>(0);
  38. }
  39. const_iterator end() const
  40. {
  41. return reinterpret_cast<const_iterator>(0);
  42. }
  43. bool empty() const
  44. {
  45. return false;
  46. }
  47. size_type size() const
  48. {
  49. return 0;
  50. }
  51. };
  52. // bounded copy algorithm -----------------------------------------------//
  53. // Bounded version of the std::copy algorithm
  54. template<typename InputIteratorT, typename OutputIteratorT>
  55. inline OutputIteratorT bounded_copy(
  56. InputIteratorT First,
  57. InputIteratorT Last,
  58. OutputIteratorT DestFirst,
  59. OutputIteratorT DestLast )
  60. {
  61. InputIteratorT InputIt=First;
  62. OutputIteratorT OutputIt=DestFirst;
  63. for(; InputIt!=Last && OutputIt!=DestLast; InputIt++, OutputIt++ )
  64. {
  65. *OutputIt=*InputIt;
  66. }
  67. return OutputIt;
  68. }
  69. // iterator range utilities -----------------------------------------//
  70. // copy range functor
  71. template<
  72. typename SeqT,
  73. typename IteratorT=BOOST_STRING_TYPENAME SeqT::const_iterator >
  74. struct copy_iterator_rangeF
  75. {
  76. typedef iterator_range<IteratorT> argument_type;
  77. typedef SeqT result_type;
  78. SeqT operator()( const iterator_range<IteratorT>& Range ) const
  79. {
  80. return copy_range<SeqT>(Range);
  81. }
  82. };
  83. } // namespace detail
  84. } // namespace algorithm
  85. } // namespace boost
  86. #endif // BOOST_STRING_UTIL_DETAIL_HPP