BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslmf_isaccessiblebaseof.h
Go to the documentation of this file.
1/// @file bslmf_isaccessiblebaseof.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslmf_isaccessiblebaseof.h -*-C++-*-
8#ifndef INCLUDED_BSLMF_ISACCESSIBLEBASEOF
9#define INCLUDED_BSLMF_ISACCESSIBLEBASEOF
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslmf_isaccessiblebaseof bslmf_isaccessiblebaseof
15/// @brief Provide a compile-time check for derived classes.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslmf
19/// @{
20/// @addtogroup bslmf_isaccessiblebaseof
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslmf_isaccessiblebaseof-purpose"> Purpose</a>
25/// * <a href="#bslmf_isaccessiblebaseof-classes"> Classes </a>
26/// * <a href="#bslmf_isaccessiblebaseof-description"> Description </a>
27/// * <a href="#bslmf_isaccessiblebaseof-usage"> Usage </a>
28/// * <a href="#bslmf_isaccessiblebaseof-example-1-base-and-derived-classes"> Example 1: Base And Derived Classes </a>
29/// * <a href="#bslmf_isaccessiblebaseof-example-2-unrelated-classes"> Example 2: Unrelated Classes </a>
30///
31/// # Purpose {#bslmf_isaccessiblebaseof-purpose}
32/// Provide a compile-time check for derived classes.
33///
34/// # Classes {#bslmf_isaccessiblebaseof-classes}
35///
36/// - bslmf::IsAccessibleBaseOf: meta-function for detecting derived classes
37///
38/// # Description {#bslmf_isaccessiblebaseof-description}
39/// This component provides a meta-function,
40/// `bslmf::IsAccessibleBaseOf`, that determines whether one class is an
41/// accessible base class of another class. The static constant
42/// `bslmf::IsAccessibleBaseOf::value` is `true` if the template parameter
43/// `t_BASE` class is an accessible base class of, or the same class as, the
44/// template parameter `t_DERIVED`. Otherwise,
45/// `bslmf::IsAccessibleBaseOf::value` is `false`. The specific cases of
46/// private, protected, and ambiguous inheritance are not supported for versions
47/// of C++ prior to 11.
48///
49/// ## Usage {#bslmf_isaccessiblebaseof-usage}
50///
51///
52/// In this section we show intended use of this component.
53///
54/// ### Example 1: Base And Derived Classes {#bslmf_isaccessiblebaseof-example-1-base-and-derived-classes}
55///
56///
57/// Define two classes, one inheriting from the other.
58/// @code
59/// struct Base
60/// {};
61///
62/// struct Derived : Base
63/// {};
64/// @endcode
65/// Evaluate `bslmf::IsAccessibleBaseOf::value`.
66/// @code
67/// void example1()
68/// {
69/// assert((true == bslmf::IsAccessibleBaseOf<Base, Derived>::value));
70/// assert((true == bslmf::IsAccessibleBaseOf<Base, Base> ::value));
71/// assert((true == bslmf::IsAccessibleBaseOf<Derived, Derived>::value));
72/// assert((false == bslmf::IsAccessibleBaseOf<Derived, Base> ::value));
73/// }
74/// @endcode
75/// ### Example 2: Unrelated Classes {#bslmf_isaccessiblebaseof-example-2-unrelated-classes}
76///
77///
78/// Define two classes, one inheriting privately from the other.
79/// @code
80/// class Unrelated
81/// {};
82///
83/// class Unrelated2
84/// {};
85/// @endcode
86/// Evaluate `bslmf::IsAccessibleBaseOf::value`. Note that `Derived` is not
87/// *observably* derived from `Base`, so std::is_base_of would evaluate `true`,
88/// but `bslmf::IsAccessibleBaseOf` evaluates `false`.
89/// @code
90/// void example2()
91/// {
92/// assert((false ==
93/// bslmf::IsAccessibleBaseOf<Unrelated, Unrelated2>::value));
94/// }
95/// @endcode
96/// @}
97/** @} */
98/** @} */
99
100/** @addtogroup bsl
101 * @{
102 */
103/** @addtogroup bslmf
104 * @{
105 */
106/** @addtogroup bslmf_isaccessiblebaseof
107 * @{
108 */
109
110#include <bslscm_version.h>
111
113#include <bslmf_isclass.h>
114#include <bslmf_isconvertible.h>
115#include <bslmf_removecv.h>
116
117
118namespace bslmf {
119
120 // ========================
121 // class IsAccessibleBaseOf
122 // ========================
123
124/// This `struct` template provides a type trait to determine if one class
125/// is an accessible base class of another class. Note that, while similar
126/// to `std::is_base_of`, when the derived relationship is via private,
127/// protected, or ambiguous inheritance `IsAccessibleBaseOf` evaluates to
128/// false.
129template <class t_BASE, class t_DERIVED>
132 bool,
133 bsl::is_class<typename bsl::remove_cv<t_BASE>::type>::value &&
134 bsl::is_class<typename bsl::remove_cv<t_DERIVED>::type>::value &&
135 bsl::is_convertible<
136 typename bsl::remove_cv<t_DERIVED>::type *,
137 typename bsl::remove_cv<t_BASE>::type *>::value> {
138};
139
140} // close package namespace
141
142
143#endif // INCLUDED_BSLMF_ISACCESSIBLEBASEOF
144
145// ----------------------------------------------------------------------------
146// Copyright 2022 Bloomberg Finance L.P.
147//
148// Licensed under the Apache License, Version 2.0 (the "License");
149// you may not use this file except in compliance with the License.
150// You may obtain a copy of the License at
151//
152// http://www.apache.org/licenses/LICENSE-2.0
153//
154// Unless required by applicable law or agreed to in writing, software
155// distributed under the License is distributed on an "AS IS" BASIS,
156// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
157// See the License for the specific language governing permissions and
158// limitations under the License.
159// ----------------------------- END-OF-FILE ----------------------------------
160
161/** @} */
162/** @} */
163/** @} */
Definition bslmf_isaccessiblebaseof.h:137
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlbb_blob.h:576
Definition bslmf_integralconstant.h:244