BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlb_testinputiterator.h
Go to the documentation of this file.
1/// @file bdlb_testinputiterator.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bdlb_testinputiterator.h -*-C++-*-
8#ifndef INCLUDED_BDLB_TESTINPUTITERATOR
9#define INCLUDED_BDLB_TESTINPUTITERATOR
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bdlb_testinputiterator bdlb_testinputiterator
15/// @brief Provide a pure input iterator for an empty range.
16/// @addtogroup bdl
17/// @{
18/// @addtogroup bdlb
19/// @{
20/// @addtogroup bdlb_testinputiterator
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bdlb_testinputiterator-purpose"> Purpose</a>
25/// * <a href="#bdlb_testinputiterator-classes"> Classes </a>
26/// * <a href="#bdlb_testinputiterator-description"> Description </a>
27/// * <a href="#bdlb_testinputiterator-usage"> Usage </a>
28/// * <a href="#bdlb_testinputiterator-example-1-basic-use-of-bdlb-testinputiterator"> Example 1: Basic Use of bdlb::TestInputIterator </a>
29///
30/// # Purpose {#bdlb_testinputiterator-purpose}
31/// Provide a pure input iterator for an empty range.
32///
33/// @deprecated Use @ref bsltf_testinputiterator instead.
34///
35/// # Classes {#bdlb_testinputiterator-classes}
36///
37/// - bdlb::TestInputIterator: empty input iterator template
38///
39/// # Description {#bdlb_testinputiterator-description}
40/// This components provides a mechanism,
41/// `bdlb::TestInputIterator`, that defines an input iterator with the following
42/// attributes:
43///
44/// * For a given type, `T`, all objects of type `TestInputIterator<T>`
45/// compare equal. Thus, any pair of such iterators constitute an
46/// empty range.
47/// * Dereferencing or incrementing the iterator is undefined behavior, since
48/// every iterator is logically at the end of its valid range.
49/// * Exactly meets the requirements for an input iterator according to the
50/// C++ Standard (C++98, Section 24.1.1 [lib.input.iterators]).
51///
52/// This iterator type is typically used to check algorithms for compatibility
53/// with input iterators. The goal is to make sure that their code is able to
54/// work even with the most restrictive input iterator.
55///
56/// ## Usage {#bdlb_testinputiterator-usage}
57///
58///
59/// This section illustrates intended use of this component.
60///
61/// ### Example 1: Basic Use of bdlb::TestInputIterator {#bdlb_testinputiterator-example-1-basic-use-of-bdlb-testinputiterator}
62///
63///
64/// In the following example we use a `bdlb::TestInputIterator` to test that an
65/// aggregation function compiles when instantiated with a pure input iterator.
66///
67/// First, we define a function `sum` that accepts two input iterators and
68/// returns the sum of all elements in range specified by them.
69/// @code
70/// template <class IN_ITER>
71/// typename bsl::iterator_traits<IN_ITER>::value_type
72/// sum(IN_ITER first, IN_ITER last)
73/// {
74/// typename bsl::iterator_traits<IN_ITER>::value_type total = 0;
75/// while (first != last) {
76/// total += *first++;
77/// }
78/// return total;
79/// }
80/// @endcode
81/// Now, we define a function `testSum` that first verifies that `sum` correctly
82/// accumulates a sum, and then verifies, using `bdlb::TestInputIterator`, that
83/// `sum` can be instantiated on an iterator that strictly matches the
84/// requirements of an empty input iterator:
85/// @code
86/// int testSum()
87/// {
88/// static const int myArray[6] = { 2, 3, 5, 7, 11, 0 };
89///
90/// // Verify that `sum` correctly computes the sum using random access
91/// // iterators (pointers).
92/// int r1 = sum(&myArray[0], &myArray[5]);
93/// assert(28 == r1);
94///
95/// // Verify that `sum` can be instantiated using a pure input iterator.
96/// typedef bdlb::TestInputIterator<unsigned> iterType;
97/// unsigned r2 = sum(iterType(), iterType());
98/// assert(0 == r2);
99///
100/// return 0;
101/// }
102/// @endcode
103/// @}
104/** @} */
105/** @} */
106
107/** @addtogroup bdl
108 * @{
109 */
110/** @addtogroup bdlb
111 * @{
112 */
113/** @addtogroup bdlb_testinputiterator
114 * @{
115 */
116
117#include <bdlscm_version.h>
118
119#include <bsltf_inputiterator.h>
120
122
123#include <bsl_iterator.h>
124
125
126namespace bdlb {
127
128 // =======================
129 // class TestInputIterator
130 // =======================
131
132#if defined(BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES)
133
134template <class TYPE>
135using TestInputIterator = bsltf::InputIterator<TYPE>;
136
137#else
138
139template <class TYPE>
141 // CREATORS
143
144 TestInputIterator(const TestInputIterator& original);
145};
146
147 // -----------------------
148 // class TestInputIterator
149 // -----------------------
150
151// CREATORS
152template <class TYPE>
153inline
155: bsltf::InputIterator<TYPE>()
156{}
157
158template <class TYPE>
159inline
161: bsltf::InputIterator<TYPE>(original)
162{}
163
164#endif
165
166} // close package namespace
167
168
169#endif
170
171// ----------------------------------------------------------------------------
172// Copyright 2015 Bloomberg Finance L.P.
173//
174// Licensed under the Apache License, Version 2.0 (the "License");
175// you may not use this file except in compliance with the License.
176// You may obtain a copy of the License at
177//
178// http://www.apache.org/licenses/LICENSE-2.0
179//
180// Unless required by applicable law or agreed to in writing, software
181// distributed under the License is distributed on an "AS IS" BASIS,
182// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
183// See the License for the specific language governing permissions and
184// limitations under the License.
185// ----------------------------- END-OF-FILE ----------------------------------
186
187/** @} */
188/** @} */
189/** @} */
Definition bsltf_inputiterator.h:162
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlb_algorithmworkaroundutil.h:74
Definition bsltf_allocargumenttype.h:92
Definition bdlb_testinputiterator.h:140
TestInputIterator()
Definition bdlb_testinputiterator.h:154