Prev: Repeat a typedef or include a header with the typedef?
Next: needing std::iostream as an array of bytes
From: Alex Strickland on 24 Feb 2010 15:29 Seungbeom Kim wrote: > I should align the text when the 'for' statement goes multiple lines: > > for (std::map<std::string, int>::const_iterator i = member_ages.begin(); > i != member_ages.end(); ++i) { > // body > } > > No matter how I did it, it wasn't satisfactory. :( I always use a second tab to further indent the second (or third) part of lines that are too long. Alex -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Chris M. Thomasson on 24 Feb 2010 15:26 "Hakusa(a)gmail.com" <hakusa(a)gmail.com> wrote in message news:bfdcc972-7f40-451c-9c57-d6e7b6d088d9(a)z35g2000yqd.googlegroups.com... > Firstly, this seems like something there'd already be a topic about, > but i didn't see it. Also, i'm not sure if this is the right place to > ask, but... > > What C++0x features are most relevant to you? [...] That would have to be: __________________________________________ std::thread std::mutex std::condition_variable std::atomic<T> __________________________________________ -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Klaus Rudolph on 25 Feb 2010 15:56 Hakusa(a)gmail.com schrieb: > > What C++0x features are most relevant to you? * lambdas! * delegating constructors. * unique initializer lists for all data types I think the actual upcoming standard looks more straightforward. A lot things become much clearer. But one of the new disadvantages: lambda pointers could only be used in templates and the type is 'unknown'. I have not found a reason for that behavior. Maybe this will be corrected in the next release :-) A generic functor could be used as workaround. But this not as cool as it could be . -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Hakusa on 25 Feb 2010 15:57 On Feb 24, 7:24 am, SG <s.gesem...(a)gmail.com> wrote: > On 24 Feb., 01:18, "Hak...(a)gmail.com" <hak...(a)gmail.com> wrote: > > On Feb 23, 3:00 pm, SG <s.gesem...(a)gmail.com> wrote: > > > On 23 Feb., 03:51, "Hak...(a)gmail.com" <hak...(a)gmail.com> wrote: > > > > [...] > > > But rvalue references would not help you in such cases (unless the > > > array's elements can be moved much faster than copied). Rvalue > > > references are great in case "logical members" are heap-allocated and > > > only referenced through a pointer member (see std::vector, for > > > example). > > > The way i use rvalue references is in the operator+ function: > > > // Pseudo code > > template< T1, T2, S > > > Vector<T2,S>&& operator+( const Vector<T1,S>& a, Vector<T2,S>&& b ) > > { > > b += a; > > return std::move(b); > > } > > > Rather than creating a vector with a+b, then another with (a+b)+c, it > > should create a temporary with a+b, then add c onto (a+b), then copy > > that into d. > > You mean a+(b+c), right? Only the 2nd parameter of this operator+ > function is an rvalue reference. Implicitly, there's a function where the rvalue ref is on the other side. Sorry about that; i considered writing both, but thought one was enough. > Anyhow, I'd consider it unsafe and it > is likely not worth the hassle of writing this overload. I would guess > that this doesn't safe any significant amount of time (Have you > measured it?). No. I wrote that it is of interest to me, and i haven't measured anything yet, but without it being interesting to me, and without writing the function, i couldn't find out. Besides, i didn't start this thread to talk about my usage, but my and other's interest, and using rvalue references for this kind of operation was introduced to me by the VC++ blog; i just happen to find the concept cool. > It's unsafe because it allows you to write things like > > auto const& foo = a + (b + c); > The current draft N3035 still contains some operator+ functions for > strings which return rvalue references. But my understanding is that > this is going to be replaced. See LWG issue #1138:http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3018.html#1138 Interesting you note that! What introduced me to the idea of using rvalue references for this purpose is reading about just this use of them on the VC++ blog. I guess it makes sense; even if i think using auto with any kind of zeal is bad, reserving it for cases where there is much more ambiguity than here, i can see how that creates a more fool-proof program... Thank you for bringing my attention to that! -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Florian Weimer on 25 Feb 2010 16:35 * Mathias Gaunard: F> On Feb 24, 12:18 am, "Hak...(a)gmail.com" <hak...(a)gmail.com> wrote: > >> The way i use rvalue references is in the operator+ function: >> >> // Pseudo code >> template< T1, T2, S > >> Vector<T2,S>&& operator+( const Vector<T1,S>& a, Vector<T2,S>&& b ) >> { >> b += a; >> return std::move(b); >> >> } > > This realize this modifies its right operand, which isn't something > operator+ should do? > Did you mean to only apply that to non-lvalues? AFAIK, && only binds to rvalues, not lvalues anymore. Apparently, N2844 was adopted into the draft standard. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 5 Prev: Repeat a typedef or include a header with the typedef? Next: needing std::iostream as an array of bytes |