Skip to content

Instantly share code, notes, and snippets.

@anders-sjogren
Created December 15, 2014 12:10
Show Gist options
  • Save anders-sjogren/4cfea1017ac2620732f7 to your computer and use it in GitHub Desktop.
Save anders-sjogren/4cfea1017ac2620732f7 to your computer and use it in GitHub Desktop.
Code showing the difference in lookup behaviour for functions and callable objects, in connection to argument-dependent lookup
#include <iostream>
#include <string>
namespace adl_ns {
struct X{};
std::string f(const X&){return "f from ADL namespace";}
std::string g(const X&){return "g from ADL namespace";}
}
namespace using_ns {
template<class T>
std::string f(const T&){
return "f from using namespace";
}
struct G {
constexpr G() = default;
template<class T>
constexpr std::string operator()(const T&) {
return "g from using namespace";
}
};
constexpr G g{};
}
int main()
{
using namespace using_ns;
adl_ns::X x;
std::cout << f(x) << std::endl;
std::cout << g(x) << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment