I’m looking for a simple example when C++ 23 auto(x) could be useful.
This is what I have so far:
struct A {
A() = default;
explicit A(const A&) {} // copy constructor
};
struct B {
A child;
};
template<class T>
void printChild(T t) {
}
template<class T>
void printParent(T t) {
// printChild(t.child); // Error - copy ctr is explicit
printChild(A(t.child)); // if we knew the type
printChild(auto(t.child)); // in C++23
}
int main() {
B b;
printParent(b);
}
Now I’m looking for a simple example without an explicit constructor, and perhaps another one where the decay_copy benefit is shown. The examples I’ve found online so far have not been clear to me.