2012/7/16 Ion Gaztaņaga <igaztanaga@gmail.com>
El 16/07/2012 13:54, Krzysztof Czainski escribiķ:
Version 1: C++03 vs. C++0x:
- the last 4 use cases {{{ ptr<A> b = make_b(); ptr<A> c( make_b() ); a
= make_a(); b = make_b(); }}} introduce a deep copy in version C++03,
while while the deep copy is avoided in C++0x.
Thanks for the report. It's a pity that current move emulation does not catch rvalues of convertible types to avoid the copy. Maybe for the last two cases you could try with BOOST_COPY_ASSIGN_REF(ptr<U>) to see if the deep copy is avoided.
Best,
Ion
Thanks for the suggestion, Ion. I had tried that before, but it caused compiler errors. Replacing one line
operator=( ptr<U> const& b )
with
operator=( BOOST_COPY_ASSIGN_REF(ptr<U>) b )
results in compiler errors:
..\main.cpp:76:9: error: no match for 'operator=' in 'x = h'
..\/ptr.hpp:53:5: note: candidates are: ptr<T>& ptr<T>::operator=(ptr<T>&) [with T = A, ptr<T> = ptr<A>]
..\/ptr.hpp:69:10: note: ptr<T>& ptr<T>::operator=(const boost::rv<ptr<T> >&) [with T = A, ptr<T> = ptr<A>]
..\/ptr.hpp:77:10: note: ptr<T>& ptr<T>::operator=(boost::rv<ptr<T> >&) [with T = A, ptr<T> = ptr<A>]
..\main.cpp:88:9: error: no match for 'operator=' in 'b = make_b()()'
..\/ptr.hpp:53:5: note: candidates are: ptr<T>& ptr<T>::operator=(ptr<T>&) [with T = A, ptr<T> = ptr<A>]
..\/ptr.hpp:69:10: note: ptr<T>& ptr<T>::operator=(const boost::rv<ptr<T> >&) [with T = A, ptr<T> = ptr<A>]
..\/ptr.hpp:77:10: note: ptr<T>& ptr<T>::operator=(boost::rv<ptr<T> >&) [with T = A, ptr<T> = ptr<A>]
Regards
Kris