BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bdlf_noop.h
Go to the documentation of this file.
1/// @file bdlf_noop.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bdlf_noop.h -*-C++-*-
8#ifndef INCLUDED_BDLF_NOOP
9#define INCLUDED_BDLF_NOOP
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bdlf_noop bdlf_noop
15/// @brief Provide a functor class that does nothing.
16/// @addtogroup bdl
17/// @{
18/// @addtogroup bdlf
19/// @{
20/// @addtogroup bdlf_noop
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bdlf_noop-purpose"> Purpose</a>
25/// * <a href="#bdlf_noop-classes"> Classes </a>
26/// * <a href="#bdlf_noop-description"> Description </a>
27/// * <a href="#bdlf_noop-usage"> Usage </a>
28/// * <a href="#bdlf_noop-example-1-an-unwanted-bsl-function-callback"> Example 1: An Unwanted bsl::function Callback </a>
29/// * <a href="#bdlf_noop-example-2-an-unwanted-template-type-callback"> Example 2: An Unwanted Template Type Callback </a>
30///
31/// # Purpose {#bdlf_noop-purpose}
32/// Provide a functor class that does nothing.
33///
34/// # Classes {#bdlf_noop-classes}
35///
36/// - bdlf::NoOp: Functor that accepts any parameters and does nothing.
37///
38/// # Description {#bdlf_noop-description}
39/// This component provides a class, `bdlf::NoOp`, that is a
40/// functor whose function-call operator accepts any number of arguments, does
41/// nothing (leaving all arguments unmodified), and returns `void`. On platforms
42/// where `inline` `constexpr` variables are supported, this component also
43/// provides `bdlf::noOp`, which is a `constexpr` variable of type `bdlf::NoOp`.
44///
45/// ## Usage {#bdlf_noop-usage}
46///
47///
48/// This section illustrates intended use of this component.
49///
50/// ### Example 1: An Unwanted bsl::function Callback {#bdlf_noop-example-1-an-unwanted-bsl-function-callback}
51///
52///
53/// Asynchronous systems often provide callback-based interfaces that invoke
54/// supplied callbacks at later points in time, often when an event has
55/// occurred, like the receipt of a data packet on an internet socket.
56/// Occasionally, we may need to supply these interfaces with a callback even
57/// though there's nothing we need the callback to do. In these cases, it's
58/// often possible to supply a "no-op" callback that does nothing.
59///
60/// Consider, for example, the following hypothetical interface to an
61/// asynchronous system:
62/// @code
63/// struct MyAsyncSystemUtil {
64/// // TYPES
65/// typedef bsl::function<void(int)> StatusReceivedCallback;
66/// // 'StatusReceivedCallback' is an alias for a callback functor that
67/// // takes as an argument an integer status indicating success (0),
68/// // or failures (any non-zero value).
69///
70/// static void sendPing(const StatusReceivedCallback& callback);
71/// // Send a message to the server that this client is still active.
72/// // Invoke the specified 'callback' with the value '0' on the worker
73/// // thread when this client receives, within the configured time
74/// // limit, an acknowledgement from the server that it received the
75/// // message. Otherwise, invoke the 'callback' with a non-zero value
76/// // on the worker thread after the configured time limit has expired
77/// // or the server or network responds with an error, whichever comes
78/// // first.
79/// };
80/// @endcode
81/// Suppose that we are writing a client for this system that does not need to
82/// be concerned about the status of `ping` messages sent to the server, then we
83/// can use `bdlf::NoOp` to ignore the acknowledgements:
84/// @code
85/// void example1()
86/// {
87/// MyAsyncSystemUtil::sendPing(bdlf::NoOp());
88/// }
89/// @endcode
90///
91/// ### Example 2: An Unwanted Template Type Callback {#bdlf_noop-example-2-an-unwanted-template-type-callback}
92///
93///
94/// Suppose that we are working with an asynchronous system whose interface
95/// requires a template for a callback instead of a `bsl::function`.
96///
97/// Consider, for example, the following hypothetical interface to an
98/// asynchronous system:
99/// @code
100/// template <class t_CALLBACK>
101/// class AsyncSystem
102/// {
103/// // This class implements an asynchronous system which does important
104/// // example work. While the important example work is being done, a
105/// // callback mechanism of type 't_CALLBACK' is used to provide estimates
106/// // about the percentage of the work that is complete. The type
107/// // 't_CALLBACK' must be callable with a single 'int' parameter [0,100].
108///
109/// // DATA
110/// t_CALLBACK d_callback; // callable that gives feedback when 'run' runs
111///
112/// public:
113/// // CREATORS
114/// explicit AsyncSystem(const t_CALLBACK& callback = t_CALLBACK());
115/// // Create a 'AsyncSystem' object which can be used to do important
116/// // example work. Optionally specify 'callback', a 't_CALLBACK',
117/// // object to be used for giving feedback about progress. If no
118/// // 'callback' is specified, a default-constructed object of type
119/// // 't_CALLBACK' will be used.
120///
121/// // MANIPULATORS
122/// void run();
123/// // Do the very important example work that this class is designed
124/// // to do. While doing said work, periodically invoke the
125/// // 'callback' object provided to the constructor with an estimated
126/// // percentage of the task complete as an 'int'.
127/// };
128/// @endcode
129/// Suppose that we are writing a client of this system that has no useful way
130/// to report the progress from the callback, then we can use `bdlf::NoOp` to
131/// ignore the progress reports:
132/// @code
133/// void example2()
134/// {
135/// AsyncSystem<bdlf::NoOp> mySystem;
136/// mySystem.run();
137/// }
138/// @endcode
139/// @}
140/** @} */
141/** @} */
142
143/** @addtogroup bdl
144 * @{
145 */
146/** @addtogroup bdlf
147 * @{
148 */
149/** @addtogroup bdlf_noop
150 * @{
151 */
152
153#include <bdlscm_version.h>
154
157
158#include <bsla_maybeunused.h>
159
161#include <bsls_keyword.h>
162
163#if BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
164// clang-format off
165// Include version that can be compiled with C++03
166// Generated on Mon Jan 13 08:32:04 2025
167// Command line: sim_cpp11_features.pl bdlf_noop.h
168
169# define COMPILING_BDLF_NOOP_H
170# include <bdlf_noop_cpp03.h>
171# undef COMPILING_BDLF_NOOP_H
172
173// clang-format on
174#else
175
176
177namespace bdlf {
178
179 // ==========
180 // class NoOp
181 // ==========
182
183/// This functor class provides a function-call operator that accepts any
184/// number of arguments of any type, does nothing (leaving the arguments
185/// unmodified), and returns `void`.
186///
187/// See @ref bdlf_noop
188class NoOp {
189
190 public:
191 // TRAITS
193
194 // TYPES
195
196 /// `result_type` is an alias to `void`, which is the type returned by
197 /// the function-call operator of this class
198 typedef void result_type;
199
200#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
201 // ACCESSORS
202
203 /// Do nothing and ignore all specified `ignored` arguments.
204 template <class... t_ARGS>
205 inline
207 const t_ARGS&... ignored) const BSLS_KEYWORD_NOEXCEPT;
208#endif
209};
210
211// BDE_VERIFY pragma: push
212// BDE_VERIFY pragma: -AQb01
213// BDE_VERIFY pragma: -TR17
214#ifdef BSLS_COMPILERFEATURES_SUPPORT_INLINE_VARIABLES
215inline
216constexpr NoOp noOp = NoOp();
217#else
218extern const NoOp noOp;
219#endif
220// BDE_VERIFY pragma: pop
221
222// ============================================================================
223// INLINE DEFINITIONS
224// ============================================================================
225
226 // ----------
227 // class NoOp
228 // ----------
229
230#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
231template <class... t_ARGS>
236#endif
237
238} // close package namespace
239
240
241#endif // End C++11 code
242
243#endif // INCLUDED_BDLF_NOOP
244
245// ----------------------------------------------------------------------------
246// Copyright 2023 Bloomberg Finance L.P.
247//
248// Licensed under the Apache License, Version 2.0 (the "License");
249// you may not use this file except in compliance with the License.
250// You may obtain a copy of the License at
251//
252// http://www.apache.org/licenses/LICENSE-2.0
253//
254// Unless required by applicable law or agreed to in writing, software
255// distributed under the License is distributed on an "AS IS" BASIS,
256// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
257// See the License for the specific language governing permissions and
258// limitations under the License.
259// ----------------------------- END-OF-FILE ----------------------------------
260
261/** @} */
262/** @} */
263/** @} */
Definition bdlf_noop.h:188
BSLS_KEYWORD_CONSTEXPR_CPP14 void operator()(const t_ARGS &... ignored) const BSLS_KEYWORD_NOEXCEPT
Do nothing and ignore all specified ignored arguments.
void result_type
Definition bdlf_noop.h:198
BSLMF_NESTED_TRAIT_DECLARATION(NoOp, bsl::is_trivially_copyable)
#define BSLA_MAYBE_UNUSED
Definition bsla_maybeunused.h:239
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
#define BSLS_KEYWORD_CONSTEXPR_CPP14
Definition bsls_keyword.h:631
#define BSLS_KEYWORD_NOEXCEPT
Definition bsls_keyword.h:674
Definition bdlf_bind.h:979
const NoOp noOp
Definition bslmf_istriviallycopyable.h:324