BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslmf_nil.h
Go to the documentation of this file.
1/// @file bslmf_nil.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslmf_nil.h -*-C++-*-
8#ifndef INCLUDED_BSLMF_NIL
9#define INCLUDED_BSLMF_NIL
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslmf_nil bslmf_nil
15/// @brief Provide a nil type.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslmf
19/// @{
20/// @addtogroup bslmf_nil
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslmf_nil-purpose"> Purpose</a>
25/// * <a href="#bslmf_nil-classes"> Classes </a>
26/// * <a href="#bslmf_nil-description"> Description </a>
27/// * <a href="#bslmf_nil-usage"> Usage </a>
28///
29/// # Purpose {#bslmf_nil-purpose}
30/// Provide a nil type.
31///
32/// # Classes {#bslmf_nil-classes}
33///
34/// - bslmf::Nil: class representing a nil (non-existent) type.
35/// - bslmf::IsNil: meta-function to test for nil.
36///
37/// # Description {#bslmf_nil-description}
38/// `bslmf::Nil` is mainly used for template meta-programming. It
39/// is useful for providing defaults for template parameters and terminating
40/// template recursions. `bslmf::Nil` can also be used to represent an unset
41/// state (i.e., nil) in components that require one.
42///
43/// ## Usage {#bslmf_nil-usage}
44///
45///
46/// The following usage illustrates a typical use of `bslmf::Nil` as a default
47/// template parameter for another meta-function.
48/// @code
49/// template <int CONDITION,
50/// class TRUE_TYPE = bslmf::Nil,
51/// class FALSE_TYPE = bslmf::Nil>
52/// struct my_If {
53/// typedef TRUE_TYPE Type;
54/// };
55///
56/// template <class TRUE_TYPE, class FALSE_TYPE>
57/// struct my_If<0, TRUE_TYPE, FALSE_TYPE> {
58/// typedef FALSE_TYPE Type;
59/// };
60/// @endcode
61/// Next, we can use the `my_If` meta-function to implement a print function
62/// that checks whether a type has a print method (using a fictitious
63/// meta-function `my_IsPrintable`), and print the value. Note the use of
64/// `bslmf::Nil` as the type for overloading:
65/// @code
66/// template <class TYPE>
67/// void print(const TYPE& value, int)
68/// {
69/// bsl::cout << value << bsl::endl;
70/// }
71///
72/// template <class TYPE>
73/// void print(const TYPE&, bslmf::Nil)
74/// {
75/// bsl::cout << "Cannot be printed." << bsl::endl;
76/// }
77///
78/// template <class TYPE>
79/// void print(const TYPE& value)
80/// {
81/// my_If<my_IsPrintable<TYPE>::value, int>::Type Type; // default false
82/// // type is
83/// // 'bslmf::Nil'.
84/// print(value, Type());
85/// }
86/// @endcode
87/// Using the above functions, the following code:
88/// @code
89/// int x = 3;
90/// bslmf::Nil nil;
91/// @endcode
92/// Will print the following to `stdout`:
93/// @code
94/// 3
95/// Cannot be printed.
96/// @endcode
97/// Finally, the `bslmf::IsNil` meta-function returns true if the type passed to
98/// it is `bslmf::Nil`, and false otherwise:
99/// @code
100/// assert(1 == bslmf::IsNil<bslmf::Nil>::value)
101/// assert(0 == bslmf::IsNil<int>::value)
102/// assert(0 == bslmf::IsNil<char>::value)
103/// @endcode
104/// @}
105/** @} */
106/** @} */
107
108/** @addtogroup bsl
109 * @{
110 */
111/** @addtogroup bslmf
112 * @{
113 */
114/** @addtogroup bslmf_nil
115 * @{
116 */
117
118#include <bslscm_version.h>
119
121
122
123
124namespace bslmf {
125
126 // ==========
127 // struct Nil
128 // ==========
129
130/// This struct is empty and represents a nil type.
131struct Nil {
132};
133
134 // ============
135 // struct IsNil
136 // ============
137
138template <class t_T>
140};
141
142template <>
144};
145
146} // close package namespace
147
148#ifndef BDE_OPENSOURCE_PUBLICATION // BACKWARD_COMPATIBILITY
149// ============================================================================
150// BACKWARD COMPATIBILITY
151// ============================================================================
152
153#ifdef bslmf_IsNil
154#undef bslmf_IsNil
155#endif
156/// This alias is defined for backward compatibility.
157#define bslmf_IsNil bslmf::IsNil
158
159/// This alias is defined for backward compatibility.
161#endif // BDE_OPENSOURCE_PUBLICATION -- BACKWARD_COMPATIBILITY
162
163
164
165#endif
166
167// ----------------------------------------------------------------------------
168// Copyright 2013 Bloomberg Finance L.P.
169//
170// Licensed under the Apache License, Version 2.0 (the "License");
171// you may not use this file except in compliance with the License.
172// You may obtain a copy of the License at
173//
174// http://www.apache.org/licenses/LICENSE-2.0
175//
176// Unless required by applicable law or agreed to in writing, software
177// distributed under the License is distributed on an "AS IS" BASIS,
178// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
179// See the License for the specific language governing permissions and
180// limitations under the License.
181// ----------------------------- END-OF-FILE ----------------------------------
182
183/** @} */
184/** @} */
185/** @} */
bslmf::Nil bslmf_Nil
This alias is defined for backward compatibility.
Definition bslmf_nil.h:160
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlbb_blob.h:576
Definition bslmf_integralconstant.h:244
Definition bslmf_nil.h:139
This struct is empty and represents a nil type.
Definition bslmf_nil.h:131