3

Is it possible to write a user defined literal without writing using namespace xxx;. Something like <literal value><namespace>::<UDL>; For instance

namespace tostr
{
    std::string operator "" _UP(const char *str, unsigned long long int)
    {  //transformation goes here
    }       
}

int main(int argc, char** argv) 
{
    //using namespace tostr;    
    //std::string upperCase = "hello world.\n"_UP; //OK : Works perfectly.
    //Something like this
    std::string upperCase = "hello world.\n"tostr::_UP;  //????
}
Jacinto Resende
  • 343
  • 2
  • 13

1 Answers1

4

No, you cannot use namespaced literal operators without the using declaration according to C++14 standard, §13.5.8 (dunno if this exists in C++11).

If you want to limit the effect of the using declaration (eg. if you want to use the literals with same names from different namespaces), you should use {} scopes for that.

f1u77y
  • 146
  • 4