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