MySQL 9.6.0
Source Code Documentation
not_decayed.h
Go to the documentation of this file.
1// Copyright (c) 2025, Oracle and/or its affiliates.
2//
3// This program is free software; you can redistribute it and/or modify
4// it under the terms of the GNU General Public License, version 2.0,
5// as published by the Free Software Foundation.
6//
7// This program is designed to work with certain software (including
8// but not limited to OpenSSL) that is licensed under separate terms,
9// as designated in a particular file or component or in included license
10// documentation. The authors of MySQL hereby grant you an additional
11// permission to link the program and your derivative works with the
12// separately licensed software that they have either included with
13// the program or referenced in the documentation.
14//
15// This program is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License, version 2.0, for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with this program; if not, write to the Free Software
22// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
24#ifndef MYSQL_META_NOT_DECAYED_H
25#define MYSQL_META_NOT_DECAYED_H
26
27/// @file
28/// Experimental API header
29
30#include <concepts> // same_as
31#include <type_traits> // bool_constant
32
33/// @addtogroup GroupLibsMysqlMeta
34/// @{
35
36namespace mysql::meta::detail {
37
38template <class T, class... Args>
39struct Is_decayed_helper : public std::false_type {};
40
41template <class T, class U>
43 : public std::bool_constant<std::same_as<T, std::decay_t<U>>> {};
44
45} // namespace mysql::meta::detail
46
47namespace mysql::meta {
48
49/// false if `Args` is exactly one type, say `A`, and `std::decay_t<A>` equals
50/// `Type`.
51///
52/// The use case is to constrain constructors taking (variadic) forwarding
53/// reference arguments, so they cannot be invoked as copy constructor. Here is
54/// a typical example:
55///
56/// @code
57/// template <class T>
58/// class Wrapper {
59/// public:
60/// // Copy constructor
61/// Wrapper(const Wrapper &) = default;
62///
63/// // Forwarding constructor, invoking the constructor of m_wrapped.
64/// template <class... Args>
65/// requires Not_decayed<Wrapper<T>, Args_t...>
66/// Wrapper(Args &&... args) : m_wrapped(std::forward<Args>(args)...) {}
67///
68/// private:
69/// T m_wrapped;
70/// };
71///
72/// Wrapper<int> w1(1); // invokes forwarding constructor
73/// Wrapper<int> w2(w1); // invokes copy constructor
74/// @endcode
75///
76/// Here, we expect that w2's copy constructor is invoked. If we would omit the
77/// `Not_decayed` constraint, the forwarding constructor would have been
78/// "better" according to C++'s overload resolution rules. The `Not_decayed`
79/// constraint excludes the forwarding constructor from the candidates and thus
80/// makes the copy constructor be the only viable overload.
81///
82/// See also https://akrzemi1.wordpress.com/2013/10/10/too-perfect-forwarding/
83template <class Type, class... Args>
84concept Not_decayed = (!detail::Is_decayed_helper<Type, Args...>::value);
85
86} // namespace mysql::meta
87
88// addtogroup GroupLibsMysqlMeta
89/// @}
90
91#endif // ifndef MYSQL_META_NOT_DECAYED_H
false if Args is exactly one type, say A, and std::decay_t<A> equals Type.
Definition: not_decayed.h:84
mrs::interface::RestHandler::HttpResult::Type Type
Definition: handler_content_file.cc:42
#define T
Definition: jit_executor_value.cc:373
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83
Definition: is_same_as_all.h:35
Definition: is_charlike.h:36
Definition: not_decayed.h:39
Definition: dtoa.cc:595