BDE 4.14.0 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// Include version that can be compiled with C++03
165// Generated on Wed Apr 12 13:24:41 2023
166// Command line: sim_cpp11_features.pl bdlf_noop.h
167# define COMPILING_BDLF_NOOP_H
168# include <bdlf_noop_cpp03.h>
169# undef COMPILING_BDLF_NOOP_H
170#else
171
172
173namespace bdlf {
174
175 // ==========
176 // class NoOp
177 // ==========
178
179/// This functor class provides a function-call operator that accepts any
180/// number of arguments of any type, does nothing (leaving the arguments
181/// unmodified), and returns `void`.
182///
183/// See @ref bdlf_noop
184class NoOp {
185
186 public:
187 // TRAITS
189
190 // TYPES
191
192 /// `result_type` is an alias to `void`, which is the type returned by
193 /// the function-call operator of this class
194 typedef void result_type;
195
196#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
197 // ACCESSORS
198
199 /// Do nothing and ignore all specified `ignored` arguments.
200 template <class... t_ARGS>
201 inline
203 const t_ARGS&... ignored) const BSLS_KEYWORD_NOEXCEPT;
204#endif
205};
206
207// BDE_VERIFY pragma: push
208// BDE_VERIFY pragma: -AQb01
209// BDE_VERIFY pragma: -TR17
210#ifdef BSLS_COMPILERFEATURES_SUPPORT_INLINE_VARIABLES
211inline
212constexpr NoOp noOp = NoOp();
213#else
214extern const NoOp noOp;
215#endif
216// BDE_VERIFY pragma: pop
217
218// ============================================================================
219// INLINE DEFINITIONS
220// ============================================================================
221
222 // ----------
223 // class NoOp
224 // ----------
225
226#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
227template <class... t_ARGS>
232#endif
233
234} // close package namespace
235
236
237#endif // End C++11 code
238
239#endif // INCLUDED_BDLF_NOOP
240
241// ----------------------------------------------------------------------------
242// Copyright 2023 Bloomberg Finance L.P.
243//
244// Licensed under the Apache License, Version 2.0 (the "License");
245// you may not use this file except in compliance with the License.
246// You may obtain a copy of the License at
247//
248// http://www.apache.org/licenses/LICENSE-2.0
249//
250// Unless required by applicable law or agreed to in writing, software
251// distributed under the License is distributed on an "AS IS" BASIS,
252// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
253// See the License for the specific language governing permissions and
254// limitations under the License.
255// ----------------------------- END-OF-FILE ----------------------------------
256
257/** @} */
258/** @} */
259/** @} */
Definition bdlf_noop.h:184
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:194
BSLMF_NESTED_TRAIT_DECLARATION(NoOp, bsl::is_trivially_copyable)
#define BSLA_MAYBE_UNUSED
Definition bsla_maybeunused.h:239
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_KEYWORD_CONSTEXPR_CPP14
Definition bsls_keyword.h:595
#define BSLS_KEYWORD_NOEXCEPT
Definition bsls_keyword.h:632
Definition bdlf_bind.h:976
const NoOp noOp
Definition bslmf_istriviallycopyable.h:329