C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Suggest applying r-value reference template argument deducti

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
pongba@gmail.com
Guest





PostPosted: Sat Dec 10, 2005 10:25 pm    Post subject: Suggest applying r-value reference template argument deducti Reply with quote



Hi,all

While I've read through almost all the proposals about auto&decltype, I
have some questions and some suggestions. The questions( and maybe some
suggestion) are listed in another post named "Question about
auto&decltype proposal" prior to this one.

In this one, I suggest applying r-value reference template argument
deduction to auto(i.e. auto&&).
Really, the idea is quite simple, it's just I didn't saw it in the
proposals, and I was quite puzzled. Anyway, here's the example code:

int i = 0;
auto&& a = i; // because i is a l-value, auto&& is deduced to int&

this is plain, but what's more useful is that we can use it like this:

// here, if f() returns a l-value, auto&& will be deduced to T&,
otherwise T&&
auto&& ret = f();

and I also suggest restoring the use of auto as return type that is
deduced from the return statement, because by adding '&&' it seems that
auto&& can handle the return-type-l-valueness of forwarding functions
pretty well [ example:

// note that I used auto in parameter type, as I suggest restoring this
usage, too
auto&& fwd(auto t)
{
f(t);
}
-end example]

Is this neat? Without the redundant, ugly, anti-DRY 'decltype(f(t))'.
Of course I have read N1607 in which Bjarne Stroustrup lists out the
main problems of using auto as return type, but I think for plain
forwarding function templates and short function templates(they exist
widely), using auto&& as their automatic deduced return type works
pretty well and neat - just look how clean they are!
And there's more I would reason about this, I listed 'em in my previous
post named "Question about auto&decltype proposal".

By the way, the reason I suggest restoring the use of auto in the
parameter type is because I think that there's plenty of time when
people just don't care about those unnecessary 'T's or 'U's, and that's
where auto comes in and helps elide many 'template<typename T...>'
coding:-)

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.