I have a need to process URIs in one of my applications, sometimes from const char[]
literals.
My API:
namespace net {
class uri { ... }; // contains decomposed URI (path, parameters, etc)
uri parse_uri(const std::string& uri_str); // parse string and return uri instance
}
// within global namespace (this is what the question is about):
uri operator "" _uri(const char*str, const unsigned long size)
{
return net::parse_uri(std::string{str, str + size});
}
Client code:
auto x = "/static/path/here/image.jpg"_uri;
I tried defining the string conversion operator within the net
namespace, but (disimilar to other operators) it seems I have to explicitly specify access to it in client code (with using namespace net;
for example).
My question:
Does this clash with the "compiler searches for operators in the namespace of the object it applies to" rule (like it would for an operator+(uri&, uri&)
for example)? (As a rule of thumb, I assume the problem is with my code, not the compiler).
What is the best practice or policy to use here? Import the namespace / operator in client code, or pollute the global namespace (like I did)?
I am using CLang 5.1 on OS X.