BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslmf_issame.h
Go to the documentation of this file.
1/// @file bslmf_issame.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslmf_issame.h -*-C++-*-
8#ifndef INCLUDED_BSLMF_ISSAME
9#define INCLUDED_BSLMF_ISSAME
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslmf_issame bslmf_issame
15/// @brief Provide a meta-function for testing if two types are the same.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslmf
19/// @{
20/// @addtogroup bslmf_issame
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslmf_issame-purpose"> Purpose</a>
25/// * <a href="#bslmf_issame-classes"> Classes </a>
26/// * <a href="#bslmf_issame-description"> Description </a>
27/// * <a href="#bslmf_issame-usage"> Usage </a>
28/// * <a href="#bslmf_issame-example-1-determine-same-types"> Example 1: Determine Same Types </a>
29///
30/// # Purpose {#bslmf_issame-purpose}
31/// Provide a meta-function for testing if two types are the same.
32///
33/// # Classes {#bslmf_issame-classes}
34///
35/// - bsl::is_same: standard meta-function for testing if two types are the same
36/// - bsl::is_same_v: the result value of the standard meta-function
37/// - bslmf::IsSame: meta-function for testing if two types are the same
38///
39/// # Description {#bslmf_issame-description}
40/// This component defines two meta-functions, `bsl::is_same` and
41/// `BloombergLP::bslmf::IsSame` and a template variable `bsl::is_same_v`,
42/// that represents the result value of the `bsl::is_same` meta-function. All
43/// these meta-functions may be used to query whether two types are the same.
44/// Two types are the same if they name the same type having the same
45/// cv-qualifications.
46///
47/// `bsl::is_same` meets the requirements of the `is_same` template defined in
48/// the C++11 standard [meta.rel], while `bslmf::IsSame` was devised before
49/// `is_same` was standardized.
50///
51/// The two meta-functions are functionally equivalent. The major difference
52/// between them is that the result for `bsl::is_same` is indicated by the class
53/// member `value`, while the result for `bslmf::IsSame` is indicated by the
54/// class member `value`.
55///
56/// Note that `bsl::is_same` should be preferred over `bslmf::IsSame`, and in
57/// general, should be used by new components.
58///
59/// Also note that the template variable `is_same_v` is defined in the C++17
60/// standard as an inline variable. If the current compiler supports the inline
61/// variable C++17 compiler feature, `bsl::is_same_v` is defined as an
62/// `inline constexpr bool` variable. Otherwise, if the compiler supports the
63/// variable templates C++14 compiler feature, `bsl::is_same_v` is defined as a
64/// non-inline `constexpr bool` variable. See
65/// `BSLS_COMPILERFEATURES_SUPPORT_INLINE_VARIABLES` and
66/// `BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES` macros in
67/// bsls_compilerfeatures component for details.
68///
69/// ## Usage {#bslmf_issame-usage}
70///
71///
72/// In this section we show intended use of this component.
73///
74/// ### Example 1: Determine Same Types {#bslmf_issame-example-1-determine-same-types}
75///
76///
77/// Suppose that we have several pairs of types and want to assert whether
78/// the types in each pair are the same.
79///
80/// First, we define several `typedef`s:
81/// @code
82/// typedef int INT1;
83/// typedef double DOUBLE;
84/// typedef short SHORT;
85/// typedef const short CONST_SHORT;
86/// typedef int INT2;
87/// typedef int& INT_REF;
88/// @endcode
89/// Now, we instantiate the `bsl::is_same` template for certain pairs of the
90/// `typedef`s and assert the `value` static data member of each instantiation:
91/// @code
92/// assert(true == (bsl::is_same<INT1, INT2>::value));
93/// assert(false == (bsl::is_same<INT, DOUBLE>::value));
94/// @endcode
95/// Note that a `const`-qualified type is considered distinct from the
96/// non-`const` (but otherwise identical) type:
97/// @code
98/// assert(false == (bsl::is_same<SHORT, CONST_SHORT>::value));
99/// @endcode
100/// Similarly, a `t_TYPE` and a reference to `t_TYPE` (`t_TYPE&`) are distinct:
101/// @code
102/// assert(false == (bsl::is_same<INT, INT_REF>::value));
103/// @endcode
104/// Note that if the current compiler supports the variable templates C++14
105/// feature then we can re-write the snippet of code above using the
106/// `bsl::is_same_v` variable as follows:
107/// @code
108/// #ifdef BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES
109/// assert(false == (bsl::is_same_v<SHORT, CONST_SHORT>));
110/// assert(false == (bsl::is_same_v<INT, INT_REF>));
111/// #endif
112/// @endcode
113/// @}
114/** @} */
115/** @} */
116
117/** @addtogroup bsl
118 * @{
119 */
120/** @addtogroup bslmf
121 * @{
122 */
123/** @addtogroup bslmf_issame
124 * @{
125 */
126
127#include <bslscm_version.h>
128
130
132#include <bsls_keyword.h>
133
134namespace bsl {
135
136 // ==============
137 // struct is_same
138 // ==============
139
140/// This `struct` template provides a meta-function to determine whether the
141/// (template parameter) `t_TYPE1` and the (template parameter) `t_TYPE2`
142/// are the same. This generic default template derives from
143/// `bsl::false_type`. A template specialization is provided (below) that
144/// derives from `bsl::true_type`.
145template <class t_TYPE1, class t_TYPE2>
147};
148
149/// This partial specialization of `is_same` derives from `bsl::true_type`
150/// for when the (template parameter) types are the same.
151template <class t_TYPE>
152struct is_same<t_TYPE, t_TYPE> : true_type {
153};
154
155#ifdef BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES
156/// This template variable represents the result value of the `bsl::is_same`
157/// meta-function.
158template <class t_TYPE1, class t_TYPE2>
159BSLS_KEYWORD_INLINE_VARIABLE constexpr bool is_same_v =
161#endif
162
163} // close namespace bsl
164
165
166
167namespace bslmf {
168
169 // =============
170 // struct IsSame
171 // =============
172
173/// This `struct` template implements a meta-function to determine if the
174/// (template parameter) `t_TYPE1` and the (template parameter) `t_TYPE2`
175/// are the same. This `struct` derives from `bsl::true_type` if `t_TYPE1`
176/// and `t_TYPE2` are the same, and `bsl::false_type` otherwise.
177///
178/// Note that although this `struct` is functionally equivalent to
179/// `bsl::is_same`, the use of `bsl::is_same` should be preferred.
180template <class t_TYPE1, class t_TYPE2>
181struct IsSame : bsl::is_same<t_TYPE1, t_TYPE2>::type {
182};
183
184} // close package namespace
185
186
187#ifndef BDE_OPENSOURCE_PUBLICATION // BACKWARD_COMPATIBILITY
188// ============================================================================
189// BACKWARD COMPATIBILITY
190// ============================================================================
191
192#ifdef bslmf_IsSame
193#undef bslmf_IsSame
194#endif
195/// This alias is defined for backward compatibility.
196#define bslmf_IsSame bslmf::IsSame
197#endif // BDE_OPENSOURCE_PUBLICATION -- BACKWARD_COMPATIBILITY
198
199#endif
200
201// ----------------------------------------------------------------------------
202// Copyright 2013 Bloomberg Finance L.P.
203//
204// Licensed under the Apache License, Version 2.0 (the "License");
205// you may not use this file except in compliance with the License.
206// You may obtain a copy of the License at
207//
208// http://www.apache.org/licenses/LICENSE-2.0
209//
210// Unless required by applicable law or agreed to in writing, software
211// distributed under the License is distributed on an "AS IS" BASIS,
212// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
213// See the License for the specific language governing permissions and
214// limitations under the License.
215// ----------------------------- END-OF-FILE ----------------------------------
216
217/** @} */
218/** @} */
219/** @} */
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_KEYWORD_INLINE_VARIABLE
Definition bsls_keyword.h:623
Definition bdlb_printmethods.h:283
Definition bdlbb_blob.h:576
Definition bslmf_integralconstant.h:244
Definition bslmf_issame.h:146
Definition bslmf_issame.h:181