lundi 4 janvier 2016

Does declaring swap() in namespace foo and then using swap() instead of foo::swap() under the same namespace imply foo::swap()?

My question is simple. Is it safe to do the following?

Don't need any ethical advice like "Don't name your function swap()!" or whatever, please!

file1.hpp

//header guards here
#include <utility>  //includes std::swap and std::move

namespace foo 
{
    template<typename T>
    inline void swap(T& lhs, T& rhs)
    {
        T temp = std::move(lhs);
        lhs = std::move(rhs);
        rhs = std::move(temp);
    }
}

file2.cpp

#include "file1.hpp"

namespace foo
{
    void myfun(T a, T b) 
    { 
        a += b; 
        swap(a, b);  //does it imply foo::swap, because the function
                     //is declared in the foo namespace??
    } 

}

Aucun commentaire:

Enregistrer un commentaire