
Howard Hinnant wrote: swap1 time is 0.172796 seconds swap2 time is 1.3e-05 seconds
David Abrahams wrote:
Your program gives about the results I'd have expected for the case you tested, but it doesn't address what I was concerned about.
Howard's example shows that a swap overload for std::tr1::array effectively reduces the complexity of swapping a tr1::array<vector<int>,N> from O(M*N) to O(N), when the array has N vectors, each having size M. And it provides no-throw. Aren't those the issues you were concerned about? Any type that is both CopyConstructible and Assignable is Swappable, by definition. Within generic code, people typically use the well-known idiom to swap a pair of Swappable objects: // Allow argument-dependent lookup to find a custom swap. using std::swap; swap(lhs, rhs); As long as boost::swap hasn't come out of the sandbox, of course (hint)! Don't you think it /always/ makes sense to provide a custom swap overload for a Swappable type, as long as it outperforms the default std::swap, in one way or the other? Kind regards, Niels