BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslmf_booleantestable.h
Go to the documentation of this file.
1/// @file bslmf_booleantestable.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslmf_booleantestable.h -*-C++-*-
8#ifndef INCLUDED_BSLMF_BOOLEANTESTABLE
9#define INCLUDED_BSLMF_BOOLEANTESTABLE
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslmf_booleantestable bslmf_booleantestable
15/// @brief Provide an exposition-only concept `boolean-testable`.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslmf
19/// @{
20/// @addtogroup bslmf_booleantestable
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslmf_booleantestable-purpose"> Purpose</a>
25/// * <a href="#bslmf_booleantestable-classes"> Classes </a>
26/// * <a href="#bslmf_booleantestable-description"> Description </a>
27/// * <a href="#bslmf_booleantestable-usage"> Usage </a>
28/// * <a href="#bslmf_booleantestable-example-1-implementing-a-concept-for-a-predicate-expression"> Example 1: Implementing a Concept for a Predicate (Boolean) Expression </a>
29///
30/// # Purpose {#bslmf_booleantestable-purpose}
31/// Provide an exposition-only concept `boolean-testable`.
32///
33/// # Classes {#bslmf_booleantestable-classes}
34///
35/// - bslmf::BooleanTestable: standard exposition-only `boolean-testable` concept
36///
37/// # Description {#bslmf_booleantestable-description}
38/// This component provides a concept, `bslmf::BooleanTestable`,
39/// that specifies the requirements on expressions that are convertible to
40/// `bool` and for which the logical operators have the conventional semantics.
41/// For more details, please refer to [concept.booleantestable] in the ISO C++20
42/// Standard.
43///
44/// ## Usage {#bslmf_booleantestable-usage}
45///
46///
47/// This section illustrates intended use of this component.
48///
49/// ### Example 1: Implementing a Concept for a Predicate (Boolean) Expression {#bslmf_booleantestable-example-1-implementing-a-concept-for-a-predicate-expression}
50///
51///
52/// In the following example we use `bslmf::BooleanTestable` to implement a
53/// concept to determine whether applying the `<` operator to a given type
54/// produces an `if`-testable result.
55/// @code
56/// template <class t_TYPE>
57/// concept LessComparable =
58/// requires(t_TYPE v) {
59/// { v < v } -> bslmf::BooleanTestable;
60/// };
61/// @endcode
62/// Now types can be tested using this concept:
63/// @code
64/// static_assert(LessComparable<int>);
65///
66/// struct NonLessComparable { void operator<(NonLessComparable) {} };
67/// static_assert(!LessComparable<NonLessComparable>);
68/// @endcode
69/// @}
70/** @} */
71/** @} */
72
73/** @addtogroup bsl
74 * @{
75 */
76/** @addtogroup bslmf
77 * @{
78 */
79/** @addtogroup bslmf_booleantestable
80 * @{
81 */
82
83#include <bslscm_version.h>
84
86
87#ifdef BSLS_LIBRARYFEATURES_HAS_CPP20_CONCEPTS
88
89#include <concepts>
90
91
92namespace bslmf {
93
94template <class t_TYPE>
95concept BooleanTestable_Impl = std::convertible_to<t_TYPE, bool>;
96
97template <class t_TYPE>
98concept BooleanTestable =
99 // Specify the requirements on expressions that are convertible to 'bool'
100 // and for which the logical operators have the conventional semantics.
101 // Note that this is an implementation of the exposition-only concept
102 // 'boolean-testable' defined by the ISO C++20 Standard
103 // [concept.booleantestable].
104 BooleanTestable_Impl<t_TYPE> &&
105 requires(t_TYPE&& t) {
106 { !static_cast<t_TYPE&&>(t) } -> BooleanTestable_Impl;
107 };
108
109} // close package namespace
110
111#endif // BSLS_LIBRARYFEATURES_HAS_CPP20_CONCEPTS
112
113#endif
114
115// ----------------------------------------------------------------------------
116// Copyright 2023 Bloomberg Finance L.P.
117//
118// Licensed under the Apache License, Version 2.0 (the "License");
119// you may not use this file except in compliance with the License.
120// You may obtain a copy of the License at
121//
122// http://www.apache.org/licenses/LICENSE-2.0
123//
124// Unless required by applicable law or agreed to in writing, software
125// distributed under the License is distributed on an "AS IS" BASIS,
126// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
127// See the License for the specific language governing permissions and
128// limitations under the License.
129// ----------------------------- END-OF-FILE ----------------------------------
130
131/** @} */
132/** @} */
133/** @} */
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlbb_blob.h:576