C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Pass derived object by reference to single parameter delegated templated constructors

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Tue, 7 May 2024 10:36:25 +0200
So in your case, you want to have a reference type deduced (by template argument deduction), but currently [expr.type]/1 disagrees (https://timsong-cpp.github.io/cppwp/expr.type#1): If an expression initially has the type “reference to T” ([dcl.ref], [dcl.init.ref]), the type is adjusted to T prior to any further analysis.     The copy constructor is something special (compared to other constructors).   Why do you want to handle it by a template  template <typename T> base(T x) {}   and not even    template <typename T> base(T& x) {}     in the first place?     -----Ursprüngliche Nachricht----- Von:David wang via Std-Proposals <std-proposals_at_[hidden]> Gesendet:Di 07.05.2024 09:46 Betreff:[std-proposals] Pass derived object by reference to single parameter delegated templated constructors An:C++ <std-proposals_at_[hidden]>; CC:David wang <wangjufan_at_[hidden]>; On Mon, 6 May 2024 10:18:35 -0400  Jason McKesson via Std-Proposals <std-proposals_at_[hidden] <mailto:std-proposals_at_[hidden]> > wrote: >This is way too special-case to implement. It's ultimately on the user >to prevent this from happening. `base`'s constructor uses template >argument deduction. That function takes its parameter by value. If you >use template argument deduction on such a function and pass it a type >which is a reference, it will copy the parameter. This *needs* to be a >hard-and-fast rule.  It is a special case. It is a conflict between rule and best practices. But It is not the user's fault. Rules and practices may change or be refined by us.   -- Std-Proposals mailing list Std-Proposals_at_[hidden] https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2024-05-07 08:36:27