BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bsls.h
Go to the documentation of this file.
1/// @file bsls.h
2///
3///
4/// @defgroup bsls Package bsls
5/// @brief Basic Standard Library System utilities (bsls)
6/// @addtogroup bsl
7/// @{
8/// @addtogroup bsls
9/// [bsls]: group__bsls.html
10/// @{
11///
12/// # Purpose {#bsls-purpose}
13/// Provide system-level utilities for 'bsl'.
14///
15/// # Mnemonic {#bsls-mnemonic}
16/// Basic Standard Library System utilities (bsls)
17///
18/// # Description {#bsls-description}
19/// The 'bsls' package provides a variety of system utilities for use
20/// by the 'bsl' library. These utilities include:
21///
22/// * Various buffer types with different alignment properties.
23/// * Uniform exception handling, even for non-exception build targets.
24/// * A platform-dependent 64-bit integer type.
25/// * Platform-identification routines.
26/// * A timer component, and access to system time facilities.
27///
28/// Note that the above list is not meant to be exhaustive. The sections below
29/// provide more information about the individual components.
30///
31/// ## Hierarchical Synopsis
32///
33/// The 'bsls' package currently has 86 components having 16 levels of physical
34/// dependency. The list below shows the hierarchical ordering of the components.
35/// The order of components within each level is not architecturally significant,
36/// just alphabetical.
37/// @code
38/// 16. bsls_byteorder
39///
40/// 15. bsls_alignedbuffer
41/// bsls_alignment
42/// bsls_byteorderutil
43/// bsls_platformutil !DEPRECATED!
44/// bsls_systemtime
45///
46/// 14. bsls_alignmentutil
47/// bsls_bslexceptionutil
48/// bsls_fuzztest
49/// bsls_stopwatch
50/// bsls_timeinterval
51///
52/// 13. bsls_asserttest
53/// bsls_byteorderutil_impl !PRIVATE!
54/// bsls_exceptionutil
55/// bsls_fuzztestpreconditionexception
56/// bsls_nameof
57/// bsls_outputredirector
58/// bsls_preconditions
59/// bsls_spinlock
60/// bsls_timeutil
61///
62/// 12. bsls_assert
63///
64/// 11. bsls_review
65///
66/// 10. bsls_atomic
67/// bsls_bslonce
68/// bsls_log
69///
70/// 9. bsls_atomicoperations
71///
72/// 8. bsls_atomicoperations_sparc32_sun_cc !PRIVATE!
73/// bsls_atomicoperations_sparc64_sun_cc !PRIVATE!
74/// bsls_bsllock
75/// bsls_objectbuffer
76/// bsls_protocoltest
77///
78/// 7. bsls_alignmentfromtype
79/// bsls_assertimputil
80/// bsls_asserttestexception
81/// bsls_atomicoperations_sparc_sun_cc_default !PRIVATE!
82/// bsls_bsllockimpl_win32 !PRIVATE!
83/// bsls_cpp11 !DEPRECATED!
84/// bsls_libraryfeatures
85/// bsls_pointercastutil
86/// bsls_util
87///
88/// 6. bsls_alignmenttotype
89/// bsls_annotation !DEPRECATED!
90/// bsls_atomicoperations_powerpc32_aix_xlc !PRIVATE!
91/// bsls_atomicoperations_powerpc64_aix_xlc !PRIVATE!
92/// bsls_consteval
93/// bsls_keyword
94/// bsls_nullptr
95/// bsls_performancehint
96///
97/// 5. bsls_atomicoperations_all_all_clangintrinsics !PRIVATE!
98/// bsls_atomicoperations_all_all_gccintrinsics !PRIVATE!
99/// bsls_atomicoperations_arm32_win_msvc !PRIVATE!
100/// bsls_atomicoperations_arm64_win_msvc !PRIVATE!
101/// bsls_atomicoperations_arm_all_gcc !PRIVATE!
102/// bsls_atomicoperations_powerpc_aix_xlc_default !PRIVATE!
103/// bsls_atomicoperations_powerpc_all_gcc !PRIVATE!
104/// bsls_atomicoperations_x64_all_gcc !PRIVATE!
105/// bsls_atomicoperations_x64_win_msvc !PRIVATE!
106/// bsls_atomicoperations_x86_all_gcc !PRIVATE!
107/// bsls_atomicoperations_x86_win_msvc !PRIVATE!
108/// bsls_bsllockimpl_pthread !PRIVATE!
109/// bsls_compilerfeatures
110///
111/// 4. bsls_assert_macroreset !PRIVATE!
112/// bsls_asserttest_macroreset !PRIVATE!
113/// bsls_atomicoperations_default !PRIVATE!
114/// bsls_buildtarget
115/// bsls_int64 !DEPRECATED!
116/// bsls_logseverity
117/// bsls_review_macroreset !PRIVATE!
118/// bsls_stackaddressutil
119/// bsls_systemclocktype
120/// bsls_unspecifiedbool
121///
122/// 3. bsls_alignmentimp
123/// bsls_bslsourcenameparserutil
124/// bsls_bsltestutil
125/// bsls_linkcoercion
126/// bsls_stackaddressutil_plinktimestamp !PRIVATE!
127/// bsls_types
128///
129/// 2. bsls_blockgrowth
130/// bsls_bsldeprecationinformation
131/// bsls_macroincrement
132/// bsls_macrorepeat
133/// bsls_nativestd !DEPRECATED!
134/// bsls_platform
135///
136/// 1. bsls_deprecate !DEPRECATED!
137/// bsls_deprecatefeature
138/// bsls_ident
139/// @endcode
140///
141/// ## Component Synopsis
142///
143/// @ref bsls_alignedbuffer :
144/// Provide raw buffers with user-specified size and alignment.
145///
146/// @ref bsls_alignment :
147/// Provide a namespace for enumerating memory alignment strategies.
148///
149/// @ref bsls_alignmentfromtype :
150/// Provide a meta-function that maps a `TYPE` to its alignment.
151///
152/// @ref bsls_alignmentimp :
153/// Provide implementation meta-functions for alignment computation.
154///
155/// @ref bsls_alignmenttotype :
156/// Provide a meta-function mapping an `ALIGNMENT` to a primitive type.
157///
158/// @ref bsls_alignmentutil :
159/// Provide constants, types, and operations related to alignment.
160///
161/// @ref bsls_annotation : !DEPRECATED!
162/// Provide support for compiler annotations for compile-time safety.
163///
164/// @ref bsls_assert :
165/// Provide build-specific, runtime-configurable assertion macros.
166///
167/// 'bsls_assert_macroreset': !PRIVATE!
168/// Undefine all macros from `bsls_assert.h` and `bsls_review.h`.
169///
170/// @ref bsls_assertimputil :
171/// Provide utilities to implement @ref bsls_assert and @ref bsls_review .
172///
173/// @ref bsls_asserttest :
174/// Provide a test facility for assertion macros.
175///
176/// 'bsls_asserttest_macroreset': !PRIVATE!
177/// Undefine macros related to `bsls_asserttest.h`.
178///
179/// @ref bsls_asserttestexception :
180/// Provide an exception type to support testing for failed assertions.
181///
182/// @ref bsls_atomic :
183/// Provide types with atomic operations.
184///
185/// @ref bsls_atomicoperations :
186/// Provide platform-independent atomic operations.
187///
188/// 'bsls_atomicoperations_all_all_clangintrinsics': !PRIVATE!
189/// Implement atomic operations using clang `__c11_atomic_*` intrinsics
190///
191/// 'bsls_atomicoperations_all_all_gccintrinsics': !PRIVATE!
192/// Implement atomic operations using gcc `__atomic_*` intrinsics.
193///
194/// 'bsls_atomicoperations_arm32_win_msvc': !PRIVATE!
195/// Provide implementations of atomic operations for arm32/MSVC/Win.
196///
197/// 'bsls_atomicoperations_arm64_win_msvc': !PRIVATE!
198/// Provide implementations of atomic operations for arm64/MSVC/Win.
199///
200/// 'bsls_atomicoperations_arm_all_gcc': !PRIVATE!
201/// Provide implementations of atomic operations for ARM/GCC.
202///
203/// 'bsls_atomicoperations_default': !PRIVATE!
204/// Provide default implementation for atomic operations.
205///
206/// 'bsls_atomicoperations_powerpc32_aix_xlc': !PRIVATE!
207/// Provide implementations of atomic operations for PowerPC/AIX-32bit.
208///
209/// 'bsls_atomicoperations_powerpc64_aix_xlc': !PRIVATE!
210/// Provide implementations of atomic operations for PowerPC/AIX-64bit.
211///
212/// 'bsls_atomicoperations_powerpc_aix_xlc_default': !PRIVATE!
213/// Provide default base implementations of atomics for PowerPC/AIX.
214///
215/// 'bsls_atomicoperations_powerpc_all_gcc': !PRIVATE!
216/// Provide implementations of atomic operations for gcc on PowerPC
217///
218/// 'bsls_atomicoperations_sparc32_sun_cc': !PRIVATE!
219/// Provide implementations of atomic operations for Sparc/Sun (32bit).
220///
221/// 'bsls_atomicoperations_sparc64_sun_cc': !PRIVATE!
222/// Provide implementations of atomic operations for Sparc/Sun (64bit).
223///
224/// 'bsls_atomicoperations_sparc_sun_cc_default': !PRIVATE!
225/// Provide default base implementations of atomics for Sparc/Sun.
226///
227/// 'bsls_atomicoperations_x64_all_gcc': !PRIVATE!
228/// Provide implementations of atomic operations for X86_64/GCC.
229///
230/// 'bsls_atomicoperations_x64_win_msvc': !PRIVATE!
231/// Provide implementations of atomic operations for X86_64/MSVC/Win64.
232///
233/// 'bsls_atomicoperations_x86_all_gcc': !PRIVATE!
234/// Provide implementations of atomic operations for X86/GCC.
235///
236/// 'bsls_atomicoperations_x86_win_msvc': !PRIVATE!
237/// Provide implementations of atomic operations for X86/MSVC/Windows.
238///
239/// @ref bsls_blockgrowth :
240/// Provide a namespace for memory block growth strategies.
241///
242/// @ref bsls_bsldeprecationinformation :
243/// Provide a macro to control `bsl` deprecations by release version.
244///
245/// @ref bsls_bslexceptionutil :
246/// Provide functions for use in `bsl` that throw standard exceptions.
247///
248/// @ref bsls_bsllock :
249/// Provide a platform-independent mutex for use below `bslmt`.
250///
251/// 'bsls_bsllockimpl_pthread': !PRIVATE!
252/// Provide a mutex for use below `bslmt`.
253///
254/// 'bsls_bsllockimpl_win32': !PRIVATE!
255/// Provide a mutex for use below `bslmt` for windows platform.
256///
257/// @ref bsls_bslonce :
258/// Provide BSL a thread-safe way to execute code once per process.
259///
260/// @ref bsls_bslsourcenameparserutil :
261/// Provide low-level functions for parsing source file names.
262///
263/// @ref bsls_bsltestutil :
264/// Provide test utilities for `bsl` that do not use <iostream>.
265///
266/// @ref bsls_buildtarget :
267/// Provide build-target information in object files.
268///
269/// @ref bsls_byteorder :
270/// Provide byte-order manipulation macros.
271///
272/// @ref bsls_byteorderutil :
273/// Provide byte-order swapping functions.
274///
275/// 'bsls_byteorderutil_impl': !PRIVATE!
276/// Provide implementation of byte-order manipulation functions.
277///
278/// @ref bsls_compilerfeatures :
279/// Provide macros to identify compiler support for C++11 features.
280///
281/// @ref bsls_consteval :
282/// Provide macros related to compile-time evaluation.
283///
284/// @ref bsls_cpp11 : !DEPRECATED!
285/// Provide macros for C++11 forward compatibility.
286///
287/// @ref bsls_deprecate : !DEPRECATED!
288/// Provide machinery to deprecate interfaces on a per-version basis.
289///
290/// @ref bsls_deprecatefeature :
291/// Provide machinery to deprecate entities in C++ code.
292///
293/// @ref bsls_exceptionutil :
294/// Provide simplified exception constructs for non-exception builds.
295///
296/// @ref bsls_fuzztest :
297/// Provide macros for use in fuzz testing narrow-contract functions.
298///
299/// @ref bsls_fuzztestpreconditionexception :
300/// Provide an exception type for handling failed preconditions.
301///
302/// @ref bsls_ident :
303/// Provide macros for inserting SCM Ids into source files.
304///
305/// @ref bsls_int64 : !DEPRECATED!
306/// Provide namespace for platform-dependent 64-bit integer types.
307///
308/// @ref bsls_keyword :
309/// Provide macros for forward language dialect compatibility.
310///
311/// @ref bsls_libraryfeatures :
312/// Provide macros to identify native standard library features.
313///
314/// @ref bsls_linkcoercion :
315/// Provide a way to force a link-time dependency into an object.
316///
317/// 'bsls_log':
318/// Provide a namespace for low-level logging functions.
319///
320/// @ref bsls_logseverity :
321/// Enumerate a set of logging severity levels.
322///
323/// @ref bsls_macroincrement :
324/// Provide a macro to increment preprocessor numbers.
325///
326/// @ref bsls_macrorepeat :
327/// repeat a macro invocation with different numeric arguments.
328///
329/// @ref bsls_nameof :
330/// Provide a `NameOf` type for displaying template type at run-time.
331///
332/// @ref bsls_nativestd : !DEPRECATED!
333/// Define the namespace `native_std` as an alias for `::std`.
334///
335/// @ref bsls_nullptr :
336/// Provide a distinct type for null pointer literals.
337///
338/// @ref bsls_objectbuffer :
339/// Provide raw buffer with size and alignment of user-specified type.
340///
341/// @ref bsls_outputredirector :
342/// Provide a means for test drivers to redirect and inspect output.
343///
344/// @ref bsls_performancehint :
345/// Provide performance hints for code optimization.
346///
347/// @ref bsls_platform :
348/// Provide compile-time support for platform/attribute identification.
349///
350/// @ref bsls_platformutil : !DEPRECATED!
351/// Provide consistent interface for platform-dependent functionality.
352///
353/// @ref bsls_pointercastutil :
354/// Provide function to cast between function and data pointers.
355///
356/// @ref bsls_preconditions :
357/// Provide macros for use in fuzz testing narrow contract functions.
358///
359/// @ref bsls_protocoltest :
360/// Provide classes and macros for testing abstract protocols.
361///
362/// @ref bsls_review :
363/// Provide assertion macros to safely identify contract violations.
364///
365/// 'bsls_review_macroreset': !PRIVATE!
366/// Test driver utility to undefine all macros from `bsls_review.h`.
367///
368/// @ref bsls_spinlock :
369/// Provide a spin lock.
370///
371/// @ref bsls_stackaddressutil :
372/// Provide a utility for obtaining return addresses from the stack.
373///
374/// 'bsls_stackaddressutil_plinktimestamp': !PRIVATE!
375/// Declare and weakly define a `plink_timestamp___` global variable.
376///
377/// @ref bsls_stopwatch :
378/// Provide access to user, system, and wall times of current process.
379///
380/// @ref bsls_systemclocktype :
381/// Enumerate the set of system clock types.
382///
383/// @ref bsls_systemtime :
384/// Provide utilities to retrieve the system time.
385///
386/// @ref bsls_timeinterval :
387/// Provide a representation of a time interval.
388///
389/// @ref bsls_timeutil :
390/// Provide a platform-neutral functional interface to system clocks.
391///
392/// @ref bsls_types :
393/// Provide a consistent interface for platform-dependent types.
394///
395/// @ref bsls_unspecifiedbool :
396/// Provide a class supporting the `unspecified bool` idiom.
397///
398/// @ref bsls_util :
399/// Provide essential, low-level support for portable generic code.
400///
401/// ## Component Overview
402///
403/// This section provides a brief introduction to some of the components in the
404/// 'bsls' package. See the documentation in each component for full details.
405///
406/// ### @ref bsls_alignedbuffer
407///
408/// The {@ref bsls_alignedbuffer } component provides a parameterized buffer type with
409/// a user-specified compile-time size and user-specified alignment. Typically,
410/// such a type is used in situations where it is desirable to allocate a block of
411/// properly-aligned raw memory from somewhere other than the heap, e.g., on the
412/// stack or within an aggregate object, including within a union. It is a
413/// convenient way to create a small heap from which one or more objects are
414/// allocated at run-time.
415///
416/// ### @ref bsls_alignment
417///
418/// The {@ref bsls_alignment } component computes (at compile-time) platform-dependent
419/// alignment information. This component also provides a namespace for a suite
420/// of compile-time constants and pure procedures that yield platform-dependent
421/// alignment information for primitive and user-defined types, including the
422/// maximum alignment for any type and the smallest fundamental type requiring
423/// maximum alignment. These functions, used in conjunction, are especially
424/// useful for creating pools and allocators that rely on efficient alignment.
425///
426/// ### @ref bsls_alignmentfromtype
427///
428/// The {@ref bsls_alignmentfromtype } component provides a meta-function that
429/// provides the alignment for a 'TYPE' template parameter.
430///
431/// ### @ref bsls_alignmentimp
432///
433/// The {@ref bsls_alignmentimp } component provides a suite of template
434/// meta-functions that can be used to compute (at compile-time) various
435/// platform-dependent alignment information.
436///
437/// ### @ref bsls_alignmenttotype
438///
439/// The {@ref bsls_alignmenttotype } component provides a meta-function that defines a
440/// primitive type with an alignment matching a 'ALIGNMENT' template parameter.
441///
442/// ### @ref bsls_alignmentutil
443///
444/// The {@ref bsls_alignmentutil } component provides a suite of template
445/// meta-functions that can be used to compute (at compile-time) various
446/// platform-dependent alignment information.
447///
448/// ### @ref bsls_annotation
449///
450/// The {@ref bsls_annotation } component provides a suite of preprocessor macros that
451/// define compiler-specific compile-time annotations.
452///
453/// ### @ref bsls_assert
454///
455/// The {@ref bsls_assert } component provides a set of "assert-like" macros to
456/// implement a compile-time-selectable and run-time-configurable "defensive" or
457/// "safe" mode. It also provides a suite of "assert-failure handler" methods
458/// suitable for runtime loading into the macros, via also provided methods.
459/// Users may supply their own handler methods matching the proper signature. To
460/// allow the user more flexibility in changing handlers during program execution,
461/// this component also provides a scoped guard that allows safe, temporary
462/// changing of the failure handler in a limited scope.
463///
464/// ### @ref bsls_asserttest
465///
466/// The {@ref bsls_asserttest } component provides a facility to test that
467/// 'BSLS_ASSERT_*' macros are used as intended, in the appropriate build modes,
468/// and have the expected effects.
469///
470/// ### @ref bsls_asserttestexception
471///
472/// The {@ref bsls_asserttestexception } component implements an exception class,
473/// 'bsls::AssertTestException', that provides a mechanism to convey context
474/// information from a failing assertion to a test handler.
475///
476/// ### @ref bsls_atomic
477///
478/// The {@ref bsls_atomic } component provides classes with atomic operations for
479/// 'int', 'Int64', and pointer types.
480///
481/// ### @ref bsls_atomicoperations
482///
483/// The {@ref bsls_atomicoperations } component provides a set of platform-independent
484/// atomic operations for fundamental data types, such as 32-bit and 64-bit
485/// integer and pointer.
486///
487/// ### @ref bsls_blockgrowth
488///
489/// The {@ref bsls_blockgrowth } component enumerates the supported block growth
490/// strategies.
491///
492/// ### @ref bsls_bsltestutil
493///
494/// The {@ref bsls_bsltestutil } component provides the standard printing macros used
495/// in BDE-style test drivers.
496///
497/// ### @ref bsls_buildtarget
498///
499/// The {@ref bsls_buildtarget } component defines types and runtime constants for
500/// identifying the build target information (usually specified to the compiler
501/// via a set of 'BDE_BUILD_*' macros). This is mostly useful for retrieving such
502/// information from a linkable or executable binary.
503///
504/// ### @ref bsls_byteorder
505///
506/// The {@ref bsls_byteorder } component provides a set host-to-network and
507/// network-to-host byte-order manipulation macros.
508///
509/// ### @ref bsls_compilerfeatures
510///
511/// The {@ref bsls_compilerfeatures } component provides a suite of preprocessor
512/// macros to identify compiler-specific support of language features that may not
513/// be available on all compilers in use across an organization.
514///
515/// ### @ref bsls_deprecate
516///
517/// The {@ref bsls_deprecate } component provides a suite of macros to control (on a
518/// per-version, per-UOR basis) the deprecation of functions, user-defined types,
519/// and 'typedef's.
520///
521/// ### @ref bsls_exceptionutil
522///
523/// The {@ref bsls_exceptionutil } component provides macros to replace 'try', 'throw'
524/// and 'catch'. These macros expand to normal exception constructs when
525/// exceptions are enabled and to reasonable alternatives (usually no-ops) when
526/// exceptions are disabled, allowing code that uses 'try', 'throw' and 'catch'
527/// constructs to compile even if exceptions are disabled using a compiler switch.
528///
529/// ### @ref bsls_ident
530///
531/// The {@ref bsls_ident } component provides macros for inserting SCM (Source Control
532/// Management) Ids into source files.
533///
534/// ### @ref bsls_macroincrement
535///
536/// The {@ref bsls_macroincrement } component provides a macro,
537/// 'BSLS_MACROINCREMENT(NUMBER)', that produces the preprocessor number equal to
538/// the number succeeding the supplied argument.
539///
540/// ### @ref bsls_nativestd
541///
542/// The {@ref bsls_nativestd } component defines a namespace alias, 'native_std', that
543/// serves as an alias for the 'std' namespace.
544///
545/// ### @ref bsls_nullptr
546///
547/// The {@ref bsls_nullptr } component provides a limited emulation of the C++11 type,
548/// 'std::nullptr_t', which can be used as a function parameter type to create an
549/// overload set where null pointer literals are handled specially.
550///
551/// ### @ref bsls_objectbuffer
552///
553/// The {@ref bsls_objectbuffer } component provides a parameterized buffer type,
554/// 'bsls_ObjectBuffer', which is compile-time sized and aligned to hold a
555/// specified object type. Defining a 'bsls_ObjectBuffer<T>' object does not
556/// cause the constructor for 'T' to be called. Similarly, destroying the object
557/// buffer does not call the destructor for 'T'. Typically, a 'bsls_ObjectBuffer'
558/// is used in situations where efficient (e.g., stack-based) storage is required
559/// but where straightforward initialization or destruction of an object is not
560/// possible. It can also be used to create a 'union' containing non-POD element
561/// types.
562///
563/// ### @ref bsls_performancehint
564///
565/// The {@ref bsls_performancehint } component provides performance hints for the
566/// compiler or hardware.
567///
568/// ### @ref bsls_platform
569///
570/// The {@ref bsls_platform } component defines preprocessor macros that identify and
571/// describe platform-specific attributes (at compile time). These attributes
572/// consist of the types and versions of operating system, processor(s), and
573/// compiler that comprise the platform.
574///
575/// ### @ref bsls_protocoltest
576///
577/// The {@ref bsls_protocoltest } component provides classes and macros for testing
578/// abstract protocols.
579///
580/// ### @ref bsls_stopwatch
581///
582/// The {@ref bsls_stopwatch } component implements a real-time (system clock)
583/// interval timer. A 'bsls_Stopwatch' object can accumulate and return only one
584/// interval at a time, but may be started and stopped repeatedly without being
585/// reset, so the elapsed time "interval" accumulated by a single object may be
586/// from multiple, discontinuous segments of time. The non-negative total
587/// accumulated time (in seconds) is available as a 'double' value.
588///
589/// ### @ref bsls_systemclocktype
590///
591/// The {@ref bsls_systemclocktype } component provides a namespace for the 'enum'
592/// type 'bsls::SystemClockType::Enum', which enumerates the set of system clock
593/// types. A 'bsls::SystemClockType' is particularly important when providing
594/// time-out values to synchronization methods where those time-outs must be
595/// consistent in environments where the system clocks may be changed.
596///
597/// ### @ref bsls_timeutil
598///
599/// The {@ref bsls_timeutil } component provides a set of platform-neutral pure
600/// procedures to access real-time system clock functionality. High-resolution
601/// time functions intended for interval-timing return an interval in nanoseconds
602/// (1 nsec = 1E-9 sec) as a 64-bit integer.
603///
604/// ### @ref bsls_types
605///
606/// The {@ref bsls_types } component provides a namespace for a set of 'typedef's that
607/// provide a stable, portable interface to platform-dependent types.
608///
609/// ### @ref bsls_unspecifiedbool
610///
611/// The {@ref bsls_unspecifiedbool } component provides a class template that can be
612/// used to manufacture an "unspecified boolean type" that is distinct for each
613/// class that instantiates it. *Not* for use outside the 'bsl' package.
614///
615/// ### @ref bsls_util
616///
617/// The {@ref bsls_util } component provides pure functions that supply essential
618/// low-level support for implementing portable generic facilities such as might
619/// be found in the C++ standard library.
620///
621/// ## Movable and Forwarding Reference Macros And Utilities
622///
623/// Modern C++ (C++11 and later) introduces the concepts of moving and forwarding
624/// function arguments. The BDE library provides facilities to replicate these
625/// features in C++03, and also allow writing code in a way that the same code can
626/// be compiled in both C++03 and in modern C++ (where the features are natively
627/// supported). This document describes which of these BDE facilities to use in
628/// which contexts. This section assumes familiarity with movable types and the
629/// use of {@ref bslmf_movableref } for move semantics in C++03-compatible code.
630///
631/// ### Summary
632///
633/// Four utilities are to be described and their correct usage explained, and
634/// they are summarized in the following table. The term "forwarding" refers to
635/// passing a variable recieved as an argument in one function to another
636/// function, generally without altering it. The term "perfect forwarding"
637/// refers to forwarding not only the value that the argument represents, but
638/// also characterstics of the argument such as cv-qualifications, and whether it
639/// is an rvalue or an lvalue.
640///
641/// 'BSLS_COMPILERFEATURES_FORWARD_REF(T)':
642/// Used to declare a function template argument of type 'T' that is to be
643/// perfect-forwarded.
644/// 'BSLS_COMPILERFEATURES_FORWARD(T, V)':
645/// Used to perfect-forward a function template argument, 'V', of type 'T'.
646/// 'BSLMF_MOVABLEREF_DEDUCE(T)':
647/// Used to deduce the type 'T' of a templated rvalue reference argument.
648/// 'bslmf::ForwardingType' and 'bslmf::ForwardingRefType':
649/// Used to forward arguments through layers of nested calls efficiently.
650///
651/// The following sections explain in detail the contexts in which the above
652/// macros and types are used.
653///
654/// ### Perfect Forwarding
655///
656/// In modern C++, function parameters marked with double ampersands ('&&') can
657/// either be movable references or forwarding references. The difference is
658/// whether the type of the parameter excluding the '&&' is a template type of the
659/// function (templates are forwarding references, non-templates are movable
660/// references). Forwarding references are lvalues that can bind to either an
661/// lvalue reference or an rvalue reference, and can be converted back to the
662/// original reference type with 'bsl::forward'. The BDE library achieves this
663/// effect in C++03 with two macros, 'BSLS_COMPILERFEATURES_FORWARD_REF' and
664/// 'BSLS_COMPILERFEATURES_FORWARD'.
665///
666/// 'BSLS_COMPILERFEATURES_FORWARD_REF(T)' is used to declare a function template
667/// argument of type 'T' that is to be perfect-forwarded.
668///
669/// 'BSLS_COMPILERFEATURES_FORWARD(T, V)' is used to perfect-forward a function
670/// template argument, 'V', of type 'T'.
671///
672/// For example:
673/// @code
674/// template <class T>
675/// void deduce(BSLS_COMPILERFEATURES_FORWARD_REF(T) t) // Forwarding reference
676/// {
677/// Forwarded tt(BSLS_COMPILERFEATURES_FORWARD(T, t)); // Perfect forwarding
678/// }
679/// @endcode
680///
681/// ### Short Complete Example
682///
683/// The following code will compile and run in any BDE-supported version of C++.
684/// @code
685/// #include <bslmf_movableref.h>
686/// #include <bslmf_util.h>
687///
688/// #include <bsls_compilerfeatures.h>
689///
690/// #include <bsl_iostream.h>
691/// #include <bsl_utility.h>
692///
693/// using namespace BloombergLP;
694///
695/// struct Forwarded;
696///
697/// // =====================================================================
698/// // Parameter 't' of function 'deduce' is a forwarding reference that is
699/// // forwarded to the constructor of local 'tt' to demonstrate being moved
700/// // or copied, depending on the type of the parameter passed.
701/// // =====================================================================
702/// template <class T>
703/// void deduce(BSLS_COMPILERFEATURES_FORWARD_REF(T) t) // Forwarding reference
704/// {
705/// Forwarded tt(BSLS_COMPILERFEATURES_FORWARD(T, t)); // Perfect forwarding
706/// }
707///
708/// struct Forwarded
709/// {
710/// // A class to demonstrate whether moving or copying is taking place
711/// Forwarded(){bsl::cout << "Default\n";}
712/// Forwarded(const Forwarded&){bsl::cout << "Copy\n";}
713/// Forwarded(bslmf::MovableRef<Forwarded>){bsl::cout << "Move\n";}
714/// };
715///
716/// int main()
717/// {
718/// Forwarded f;
719/// deduce(f); // Parameter is lvalue reference
720/// deduce(bslmf::MovableRefUtil::move(f)); // Parameter is rvalue reference
721/// }
722/// @endcode
723/// This program should output the following.
724/// @code
725/// Default
726/// Copy
727/// Move
728/// @endcode
729///
730/// ### Movable Reference to Templated Type
731///
732/// 'bslmf::MovableRef' is a template facility that provides move semantics in
733/// C++03. One common issue with 'MovableRef<T>' is its use in a context where
734/// 'T' itself is a template parameter: the compiler will be unable to deduce the
735/// type of 'T' in C++11 (or later) as one would expect. For example:
736/// @code
737/// template <class T>
738/// void f(bslmf::MovableRef<A<T> > a);
739///
740/// int main()
741/// {
742/// A<int> a1;
743/// f(bslmf::MovableRefUtil::move(a1)); // COMPILE ERROR! Can't deduce 'T'.
744/// }
745/// @endcode
746/// To deduce this type, the macro 'BSLMF_MOVABLEREF_DEDUCE' can be used, for
747/// example:
748/// @code
749/// template <class T>
750/// void g(BSLMF_MOVABLEREF_DEDUCE(A<T>) a);
751/// // A function that takes a 'MovableRef<A<T>>'
752///
753/// int main()
754/// {
755/// A<int> a2;
756/// g(bslmf::MovableRefUtil::move(a2)); // compiles!
757/// }
758/// @endcode
759/// A real world example can be found in component {@ref bdlb_nullablevalue }. The
760/// 'bdlb::NullableValue<TYPE>' constructor taking a movable reference to a
761/// 'bdlb::NullableValue<BDE_OTHER_TYPE>', with 'BDE_OTHER_TYPE' convertible to
762/// 'TYPE', uses 'BSLMF_MOVABLEREF_DEDUCE'.
763/// @code
764/// template <class BDE_OTHER_TYPE>
765/// NullableValue(BSLMF_MOVABLEREF_DEDUCE(
766/// NullableValue<BDE_OTHER_TYPE>) value,
767/// const allocator_type& allocator,
768/// typename bsl::enable_if<
769/// bsl::is_convertible<BDE_OTHER_TYPE, TYPE>::value &&
770/// !bsl::is_same<bsl::optional<BDE_OTHER_TYPE>, TYPE>::value,
771/// EnableType>::type = EnableType()); // IMPLICIT
772/// @endcode
773///
774/// ### Forwarding Parameters Through Many Layers Efficiently
775///
776/// Generic code that forwards arguments through many layers of metaprogramming
777/// templates -- e.g., 'bsl::function' and 'bsl::bind' -- can be made more
778/// efficient through judicious use of 'bslmf::ForwardingRefType'. This allows a
779/// number of small optimizations. For example, the collapse of array references
780/// to pointers that are unpacked only once, thereby reducing the number of
781/// template instantiations of the middle layers. The older
782/// 'bslmf::ForwardingType' served the same purpose, but is no longer recommended
783/// since 'bslmf::ForwardingRefType' is simpler to use.
784///
785/// *Note:* *The* *component* @ref bslmf_forwardingreftype *is* *a* *complex* *tool*
786/// *with* *a* *singular* *purpose,* *and* *occassions* *for* *its* *legitimate*
787/// *use* *are* *rare*.
788///
789///
790/// @}
791/** @} */