In C++11/14, providing move constructor/move assignment to avoid copies and get fast permutations:
Type(Type&& t) noexcept = default;
Use =default; when possible.
Use PIMPL idiom as always.
Don't allow polymorphism to complicate the client code.
i.e polymorphism is an implementation detail.
Use template to avoid having polymorphism with inheritance!
Penalty of runtime polymorphism is only payed when needed!
polymorphic types are used like any other types, including built-in types. !
Use Constructor taking arguments *_copy_ by _value_*
Let the compiler decide if it's an r-value (which avoid copy) or l-value and initialize the data member with
Type(T t) : dataMember{std::move(t)} {};
A shared_ptr to an immutable (const) object has value semantics.
This is why passing arguments by const& works!!!
Copy-on-write can be obtained using shared_ptr::unique();
Mutable polymorphic objects are _the_ exception.
Use make_shared to prevent seperate ref allocation.
Reference: std::swap
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.