Consider the following:
#include <iostream>
namespace X
{
void operator ""_test(unsigned long long x)
{
std::cout << x;
}
}
int main()
{
using namespace X;
10_test;
// 10_X::test; /* doesn't work */
}
I can refer to the user defined literal operator inside the namespace X
by an explicit using namespace X;
. Is there any way of referring to the literal operator without explicitly including the namespace? I tried the
10_X::test;
but of course doesn't work as the parser believes X
refers to the name of the operator.
X::operator ""_test(10)
works but it's clumsy.
_test
is both inX
andX::literals
. This permits people tousing namespace X::literals;
without pulling in everything fromX
, yet withinX
_test
is also available.Importing an individual literal is a bit annoying.
std
does this with bothstd::chrono
andstd::literals
andstd::chrono::literals
.inline namespace
s let you define subsections of your namespace that you think people would want to import as a block without getting the rest of it.