BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslmf_isreference.h
Go to the documentation of this file.
1/// @file bslmf_isreference.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslmf_isreference.h -*-C++-*-
8#ifndef INCLUDED_BSLMF_ISREFERENCE
9#define INCLUDED_BSLMF_ISREFERENCE
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslmf_isreference bslmf_isreference
15/// @brief Provide a meta-function to test reference types.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslmf
19/// @{
20/// @addtogroup bslmf_isreference
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslmf_isreference-purpose"> Purpose</a>
25/// * <a href="#bslmf_isreference-classes"> Classes </a>
26/// * <a href="#bslmf_isreference-description"> Description </a>
27/// * <a href="#bslmf_isreference-usage"> Usage </a>
28/// * <a href="#bslmf_isreference-example-1-verify-reference-types"> Example 1: Verify Reference Types </a>
29///
30/// # Purpose {#bslmf_isreference-purpose}
31/// Provide a meta-function to test reference types.
32///
33/// # Classes {#bslmf_isreference-classes}
34///
35/// - bsl::is_reference: standard meta-function for testing reference types
36/// - bsl::is_reference_v: the result value of the standard meta-function
37///
38/// @see
39///
40/// # Description {#bslmf_isreference-description}
41/// This component defines a meta-function, `bsl::is_reference` and
42/// a template variable `bsl::is_reference_v`, that represents the result value
43/// of the `bsl::is_class` meta-function, that may be used to query whether a
44/// type is an (lvalue or rvalue) reference type.
45///
46/// `bsl::is_reference` meets the requirements of the `is_reference` template
47/// defined in the C++11 standard [meta.unary.comp].
48///
49/// Note that the template variable `is_reference_v` is defined in the C++17
50/// standard as an inline variable. If the current compiler supports the inline
51/// variable C++17 compiler feature, `bsl::is_reference_v` is defined as an
52/// `inline constexpr bool` variable. Otherwise, if the compiler supports the
53/// variable templates C++14 compiler feature, `bsl::is_reference_v` is defined
54/// as a non-`const` `constexpr bool` variable. See
55/// `BSLS_COMPILERFEATURES_SUPPORT_INLINE_VARIABLES` and
56/// `BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES` macros in
57/// bsls_compilerfeatures component for details.
58///
59/// ## Usage {#bslmf_isreference-usage}
60///
61///
62/// In this section we show intended use of this component.
63///
64/// ### Example 1: Verify Reference Types {#bslmf_isreference-example-1-verify-reference-types}
65///
66///
67/// Suppose that we want to assert whether a set of types are (lvalue or rvalue)
68/// reference types.
69///
70/// Now, we instantiate the `bsl::is_reference` template for a non-reference
71/// type, an lvalue reference type, and an rvalue reference type, and assert the
72/// `value` static data member of each instantiation:
73/// @code
74/// assert(false == bsl::is_reference<int>::value);
75/// assert(true == bsl::is_reference<int&>::value);
76/// #if defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES)
77/// assert(true == bsl::is_reference<int&&>::value);
78/// #endif
79/// @endcode
80/// Note that rvalue reference is a feature introduced in the C++11 standand,
81/// and may not be supported by all compilers.
82///
83/// Also note that if the current compiler supports the variable templates C++14
84/// feature then we can re-write the snippet of code above using the
85/// `bsl::is_reference_v` variable as follows:
86/// @code
87/// #ifdef BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES
88/// assert(false == bsl::is_reference_v<int>);
89/// assert(true == bsl::is_reference_v<int&>);
90/// assert(true == bsl::is_reference_v<int&&>);
91/// #endif
92/// @endcode
93/// @}
94/** @} */
95/** @} */
96
97/** @addtogroup bsl
98 * @{
99 */
100/** @addtogroup bslmf
101 * @{
102 */
103/** @addtogroup bslmf_isreference
104 * @{
105 */
106
107#include <bslscm_version.h>
108
110
112#include <bsls_keyword.h>
113
114#ifndef BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
117#endif // BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
118
119namespace bsl {
120
121 // ===================
122 // struct is_reference
123 // ===================
124
125// IMPLEMENTATION NOTE: We originally implemented this trait in terms of
126// 'is_lvalue_reference' and 'is_rvalue_reference' but ran into an issue on
127// Sun where the compiler was reporting that the maximum depth of template
128// expansion was being exceeded.
129
130/// This `struct` template implements the `is_reference` meta-function
131/// defined in the C++11 standard [meta.unary.comp] to determine if the
132/// (template parameter) `t_TYPE` is a (lvalue or rvalue) reference type.
133///
134/// This `struct` derives from `bsl::false_type` with specializations to
135/// follow for lvalue and rvalue references.
136template <class t_TYPE>
138};
139
140/// This `struct` template implements the `is_reference` meta-function
141/// defined in the C++11 standard [meta.unary.comp] to determine if the
142/// (template parameter) `t_TYPE` is a (lvalue or rvalue) reference type.
143///
144/// This specialization for lvalue references derives from `bsl::true_type`.
145template <class t_TYPE>
146struct is_reference<t_TYPE&> : true_type {
147};
148
149#if defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES)
150/// This `struct` template implements the `is_reference` meta-function
151/// defined in the C++11 standard [meta.unary.comp] to determine if the
152/// (template parameter) `t_TYPE` is a (lvalue or rvalue) reference type.
153///
154/// This specialization for rvalue references derives from 'bsl::true_type.
155template <class t_TYPE>
156struct is_reference<t_TYPE&&> : true_type {
157};
158#endif
159
160#ifdef BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES
161/// This template variable represents the result value of the
162/// `bsl::is_reference` meta-function.
163template <class t_TYPE>
164BSLS_KEYWORD_INLINE_VARIABLE constexpr bool is_reference_v =
166#endif
167
168} // close namespace bsl
169
170#endif
171
172// ----------------------------------------------------------------------------
173// Copyright 2013 Bloomberg Finance L.P.
174//
175// Licensed under the Apache License, Version 2.0 (the "License");
176// you may not use this file except in compliance with the License.
177// You may obtain a copy of the License at
178//
179// http://www.apache.org/licenses/LICENSE-2.0
180//
181// Unless required by applicable law or agreed to in writing, software
182// distributed under the License is distributed on an "AS IS" BASIS,
183// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
184// See the License for the specific language governing permissions and
185// limitations under the License.
186// ----------------------------- END-OF-FILE ----------------------------------
187
188/** @} */
189/** @} */
190/** @} */
static const t_TYPE value
Definition bslmf_integralconstant.h:258
#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 bslmf_integralconstant.h:244
Definition bslmf_isreference.h:137