Ray's playground

 

Item 25: Consider support for a non-throwing swap(Effective C++)

  • Provide a swap member function when std::swap would be inefficient for your type. Make sure your swap doesn't throw exceptions.

  • If you offer a member swap, also offer a non-member swap that calls the member. For classes (not templates), specialize std::swap, too.

  • When calling swap, employ a using declaration for std::swap, then call swap without namespace qualification.

  • It's fine to totally specialize std templates for user-defined types, but never try to add something completely new to std.

posted on 2011-03-28 20:41  Ray Z  阅读(204)  评论(0编辑  收藏  举报

导航