Mar 24, 2012

[C++][C++11]

Rules:
1. Use a non-owning * or & to observe an object that will outlive you.

template<class T> auto cbegin( const T& t ) -> decltype( t.cbegin() ) { return t.cbegin(); }
template<class T> auto cend( const T& t ) -> decltype( t.cend() ) { return t.cend(); }
template<typename T, typename ...Args>
std::unique_ptr<T> make_unique( Args&& ...args )
{
    return std::unique_ptr<T>( new T( std::forward<Args>(args)... ) );
}

2. Do NOT return R&& for a function.

3. It is meaningless returning a const R&&! See, if a RVALUE can not be modified,
then we could NOT move it! Since move zero out the integrals of the RVALUE. Or there's other use~~

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.