c++ - Name lookup issue in trailing return type -
the following example illustrates question:
#include <iostream> #include <string> template <typename t> auto func(const t& x) -> decltype(to_string(x)) { using std::to_string; return to_string(x); } int main() { std::cout << func(1); } i don't want import std::to_string global namespace, not want use -> decltype(std::to_string(x)) doing disables adl. obviously, can't put using std::to_string within decltype. so, how should it?
defer namespace;
namespace activate_adl { using std::to_string; template <typename t> auto func(const t& x) -> decltype(to_string(x)) { return to_string(x); } } template <typename t> auto func(const t& x) -> decltype(activate_adl::func(x)) { return activate_dl:: func(x); } this allows adl still done, doesn't pollute global namespace.
having hit issue few times std related functions , adl, i've found deferred namespace (well named) suitable alternatives.
Comments
Post a Comment