Does C++11 change the behavior of explicitly calling std::swap to ensure ADL-located swap's are found, like boost::swap?

后端 未结 4 1717
孤街浪徒
孤街浪徒 2020-12-01 10:32

Background

Consider for this question the following code:

#include 

namespace ns
{
    struct foo
    {
        foo() : i(0) {}
              


        
4条回答
  •  北海茫月
    2020-12-01 11:20

    Well, boost::swap() dispatches to std::swap(). To have std::swap() do something similar to boost::swap() it would need to delegate somewhere else. What is this somewhere else? The standard doesn't mandate another version of swap() which provides the actual implementation. This can be done but the standard doesn't mandate it.

    Why it doesn't do it? I didn't see any proposal proposing this implementation. If someone had wanted this to do done I'm sure it would have been proposed.

提交回复
热议问题