BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslmf_memberpointertraits.h
Go to the documentation of this file.
1/// @file bslmf_memberpointertraits.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslmf_memberpointertraits.h -*-C++-*-
8#ifndef INCLUDED_BSLMF_MEMBERPOINTERTRAITS
9#define INCLUDED_BSLMF_MEMBERPOINTERTRAITS
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslmf_memberpointertraits bslmf_memberpointertraits
15/// @brief Provide meta-function to detect pointer to member traits.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslmf
19/// @{
20/// @addtogroup bslmf_memberpointertraits
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslmf_memberpointertraits-purpose"> Purpose</a>
25/// * <a href="#bslmf_memberpointertraits-classes"> Classes </a>
26/// * <a href="#bslmf_memberpointertraits-description"> Description </a>
27/// * <a href="#bslmf_memberpointertraits-usage"> Usage </a>
28///
29/// # Purpose {#bslmf_memberpointertraits-purpose}
30/// Provide meta-function to detect pointer to member traits.
31///
32/// # Classes {#bslmf_memberpointertraits-classes}
33///
34/// - bslmf::MemberPointerTraits: meta-function to get member pointer traits
35///
36/// @see bslmf_memberfunctionpointertraits
37///
38/// # Description {#bslmf_memberpointertraits-description}
39/// This component provides a meta-function,
40/// `bslmf::MemberPointerTraits`, that determines traits of a pointer-to-member
41/// type, including the type of the object that it is a member of, and the type
42/// of the member it addresses.
43///
44/// ## Usage {#bslmf_memberpointertraits-usage}
45///
46///
47/// Define the following `struct` with the following members:
48/// @code
49/// struct MyTestClass {
50/// int func1(int) { return 0; }
51/// int d_int;
52/// };
53/// @endcode
54/// In order to deduce the types of `func1` and `d_int`, we will use
55/// `bslmf::MemberPointerTraits`.
56/// @code
57/// template <class MEMBER, class CLASS, class t_TYPE>
58/// void checkMemberPointer(t_TYPE pointer)
59/// {
60/// (void) pointer;
61/// typedef typename bslmf::MemberPointerTraits<t_TYPE>::MemberType
62/// MemberType;
63/// typedef typename bslmf::MemberPointerTraits<t_TYPE>::ClassType
64/// ClassType;
65/// assert(1 == (bsl::is_same<MemberType, MEMBER>::value));
66/// assert(1 == (bsl::is_same<ClassType, CLASS>::value));
67/// }
68/// @endcode
69/// The following program should compile and run without errors:
70/// @code
71/// void usageExample()
72/// {
73/// checkMemberPointer<int(int), MyTestClass>(&MyTestClass::func1);
74/// checkMemberPointer<int, MyTestClass>(&MyTestClass::d_int);
75/// }
76/// @endcode
77/// @}
78/** @} */
79/** @} */
80
81/** @addtogroup bsl
82 * @{
83 */
84/** @addtogroup bslmf
85 * @{
86 */
87/** @addtogroup bslmf_memberpointertraits
88 * @{
89 */
90
91#include <bslscm_version.h>
92
93#include <bslmf_removecv.h>
94
95
96namespace bslmf {
97
98template <class t_TYPE>
99struct MemberPointerTraits_Imp;
100
101 // =========================
102 // class MemberPointerTraits
103 // =========================
104
105/// This utility `struct` template provides the following nested typedefs:
106///: `ClassType`: The type of the class for which the specified `t_TYPE` is
107///: a pointer to member object.
108///: `MemberType`: The type of the member object of the class for which the
109///: specified `t_TYPE` is a pointer to member object.
110/// These typedefs will only be defined if `t_TYPE` is a
111template <class t_TYPE>
113: public MemberPointerTraits_Imp<typename bsl::remove_cv<t_TYPE>::type> {
114
115 // pointer-to-member-object type. The primary (unspecialized)
116 // MemberPointerTraits_Imp template is defined and empty.
117};
118
119 // =============================
120 // class MemberPointerTraits_Imp
121 // =============================
122
123/// Empty
124template <class t_TYPE>
127
128template <class t_MEMBER_TYPE, class t_CLASS_TYPE>
129struct MemberPointerTraits_Imp<t_MEMBER_TYPE t_CLASS_TYPE::*> {
130 // TYPES
131
132 /// `ClassType` is an alias to the type of the class for which the
133 /// specified `t_TYPE` is a pointer to member object.
134 typedef t_CLASS_TYPE ClassType;
135
136 /// `MemberType` is an alias to the type of object to which the member
137 /// object points.
138 typedef t_MEMBER_TYPE MemberType;
139};
140
141} // close package namespace
142
143
144#endif // INCLUDED_BSLMF_MEMBERPOINTERTRAITS
145
146// ----------------------------------------------------------------------------
147// Copyright 2022 Bloomberg Finance L.P.
148//
149// Licensed under the Apache License, Version 2.0 (the "License");
150// you may not use this file except in compliance with the License.
151// You may obtain a copy of the License at
152//
153// http://www.apache.org/licenses/LICENSE-2.0
154//
155// Unless required by applicable law or agreed to in writing, software
156// distributed under the License is distributed on an "AS IS" BASIS,
157// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
158// See the License for the specific language governing permissions and
159// limitations under the License.
160// ----------------------------- END-OF-FILE ----------------------------------
161
162/** @} */
163/** @} */
164/** @} */
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlbb_blob.h:576
t_MEMBER_TYPE MemberType
Definition bslmf_memberpointertraits.h:138
t_CLASS_TYPE ClassType
Definition bslmf_memberpointertraits.h:134
Empty.
Definition bslmf_memberpointertraits.h:125
Definition bslmf_memberpointertraits.h:113