Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | W Karas <wkaras@yahoo.com> |
|---|---|
| Newsgroups | comp.std.c++ |
| Subject | C++11 Rvalue-references |
| Date | 2012-06-17 18:26 -0700 |
| Organization | http://groups.google.com |
| Message-ID | <217080f3-3600-4c47-92de-1689ce39a5e3@googlegroups.com> (permalink) |
Just seems like there are simpler and better ways to get the same capability. For example, add the "pseudo-type-template" std::temp<T> (T may not have a const or volatile modifier). A reference/pointer to temp<T> implicitly converts to a pointer/reference to T, and this conversion is the only valid operation on temp<T> that is directly usable. A pointer/reference to T explicitly converts, using static_cast, to a pointer/reference to temp<T> . All compiler-generated nameless temporaries are of type temp<T>. When the following 3 conditions are met: 1. An instance of temp<T> is the actual parameter to a function call. (This is considered to include the case where a member function of T is called on the temp<T> instance.) 2. Nominally the compiler would generate a call to T::~T on the instance immediately after the function call. 3. The overload of the function that is the best match to the call has a formal parameter of type temp<T> & for the actual parameter of type temp<T>. then the compiler will omit the generated call to T::~T , and instead just deallocate the memory space for the temp<T> instance. If conditions 1 and 3 but not 2 are met, the compiler should reject the nominally best-matching overload. This would cause compilation to fail if there were no other matching overloads. To enable explicit optimizations, if t is the name of an instance of T, and the expression static_cast<temp<T> &>(t) appears as a sub-expression in an expression that is an actual parameter to a function call in the block where t was constructed, the compiler will suppress generation of destructor calls for t, after said function call. The compiler will instead just deallocate the storage for t. To enable explicit optimizations involving dynamically allocated objects, the Standard would require that it will always be possible to substitute this: pt->~T(); delete static_cast<void *>(pt); for: delete pt; or: for (unsigned i = 0; i < N_elems_t; ++i) pt[i].~T(); delete static_cast<void *>(pt); for: delete [] pt; -- [ 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 — Next in thread | Find similar | Unroll thread
C++11 Rvalue-references W Karas <wkaras@yahoo.com> - 2012-06-17 18:26 -0700
Re: C++11 Rvalue-references brangdon@cix.compulink.co.uk (Dave Harris) - 2012-06-24 23:49 -0700
Re: C++11 Rvalue-references W Karas <wkaras@yahoo.com> - 2012-06-28 13:23 -0700
Re: C++11 Rvalue-references brangdon@cix.compulink.co.uk (Dave Harris) - 2012-06-29 12:15 -0700
Re: C++11 Rvalue-references Jason McKesson <jmckesson@gmail.com> - 2012-06-29 12:16 -0700
csiph-web