MySQL 9.6.0
Source Code Documentation
mysql::meta::Not_decayed Concept Reference

false if Args is exactly one type, say A, and std::decay_t<A> equals Type. More...

#include <not_decayed.h>

Concept definition

template<class Type, class... Args>
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
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83
Definition: not_decayed.h:39

Detailed Description

false if Args is exactly one type, say A, and std::decay_t<A> equals Type.

The use case is to constrain constructors taking (variadic) forwarding reference arguments, so they cannot be invoked as copy constructor. Here is a typical example:

template <class T>
class Wrapper {
public:
// Copy constructor
Wrapper(const Wrapper &) = default;
// Forwarding constructor, invoking the constructor of m_wrapped.
template <class... Args>
requires Not_decayed<Wrapper<T>, Args_t...>
Wrapper(Args &&... args) : m_wrapped(std::forward<Args>(args)...) {}
private:
T m_wrapped;
};
Wrapper<int> w1(1); // invokes forwarding constructor
Wrapper<int> w2(w1); // invokes copy constructor
#define T
Definition: jit_executor_value.cc:373
Define std::hash<Gtid>.
Definition: gtid.h:355

Here, we expect that w2's copy constructor is invoked. If we would omit the Not_decayed constraint, the forwarding constructor would have been "better" according to C++'s overload resolution rules. The Not_decayed constraint excludes the forwarding constructor from the candidates and thus makes the copy constructor be the only viable overload.

See also https://akrzemi1.wordpress.com/2013/10/10/too-perfect-forwarding/