Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Daniel Krügler<daniel.kruegler@googlemail.com> |
|---|---|
| Newsgroups | comp.std.c++ |
| Subject | Re: Should we have a core language operator for forwarding arguments? |
| Date | 2011-11-10 07:58 -0800 |
| Organization | A noiseless patient Spider |
| Message-ID | <j9fs0o$q4d$1@dont-email.me> (permalink) |
| References | <c9357619-0e59-4e69-bcb7-ba245dd10d5a@h12g2000vbf.googlegroups.com> |
On 2011-11-10 02:10, Nikolay Ivchenkov wrote:
>
> Consider the following example:
>
> template<class T>
> void f(T&&t)
> {
> g(std::forward<T>(t));
> }
>
> We can notice that parameter t contains sufficient information for
> "perfect forwarding":
>
> #define FWD(x) static_cast<decltype(x)>(x)
>
> template<class T>
> void f(T&&t)
> {
> g(FWD(t));
> }
>
> This code might be even simpler if we had unary operator&& with the
> similar semantics:
>
> &&reference returns static_cast<decltype(reference)>(reference)
>
> Example:
>
> template<class T>
> void f(T&&t)
> {
> g(&&t);
> }
>
> I think that simple things should be expressed by simple constructs.
> std::forward should be used where its function argument would not
> contain sufficient information, otherwise we supply redundant
> information and have too lengthy code (especially when std::forward is
> included in a single expression several times).
I agree, I find your example very much compelling. There are some cases,
where I still prefer using std::forward, namely where I could
(unintentionally) have tried to convert an rvalue to an lvalue as
analysed in
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2951.html
This does not happen in your examples, though.
Thanks& Greetings from Bremen,
Daniel Krügler
--
[ comp.std.c++ is moderated. To submit articles, try posting with your ]
[ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to comp.std.c++ | Previous | Next — Previous in thread | Next in thread | Find similar
Should we have a core language operator for forwarding arguments? Nikolay Ivchenkov <tsoae@mail.ru> - 2011-11-09 19:10 -0600
Re: Should we have a core language operator for forwarding arguments? Daniel Krügler<daniel.kruegler@googlemail.com> - 2011-11-10 07:58 -0800
Re: Should we have a core language operator for forwarding arguments? Arne Mertz<arnemertz@googlemail.com> - 2011-11-10 10:41 -0800
Re: Should we have a core language operator for forwarding arguments? Nikolay Ivchenkov<tsoae@mail.ru> - 2011-11-11 13:04 -0800
Re: Should we have a core language operator for forwarding arguments? Miles Bader <miles@gnu.org> - 2011-11-12 11:33 -0800
Re: Should we have a core language operator for forwarding arguments? Nikolay Ivchenkov<tsoae@mail.ru> - 2011-11-12 21:46 -0800
csiph-web