why move swap_impl in boost::swap to a separate namespace?

眉间皱痕 提交于 2019-12-06 05:10:01

If swap_impl is in the namespace boost, the call swap(left,right); in the implementation of swap_impl will resolve to boost::swap instead of std::swap. That is, boost::swap -> boost::swap_impl -> boost::swap, and thus infinite recursion.

As dyp has pointed out in the comment, the correct interpretation of the comment //use std::swap if argument dependent lookup fails should be as follows: An unqualified swap(left,right) is intended to select a specialized swapping function for the two arguments, found in the namespace of the types of those arguments. If such a specialized function has not been provided, the generic std::swap is used as a fallback.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!