2012/10/26 Andrzej Krzemieński <
akrz...@gmail.com>:
> I am reading paper N2378 (User-defined Literals - revision 3). In section
> 3.5 it recommends an idiom for defining literal operators in separate
> namespaces. But just before that it lists different approaches to namespace
> choices that it considers inferior:
>
> "It is tempting therefore to declare user-defined literal operators in the
> global namespace, or to place a global using-declaration in the global
> namespace. Unfortunately, that is a recipe for declaration conflicts even
> for code that might not use the literal forms."
>
> What does it mean to "place a global using-declaration in the global
> namespace"? The only situation that comes to my mind is this:
>
> // File a.h:
> namespace A {
> class X {};
> namespace literals {
> void operator "" _X(char const*);
> }
> }
> using A::literals::operator "" _X;
Yes, I believe that this is meant here as "global using-declaration in
the global namespace".
> // File b.h:
> namespace B {
> class ExtNum {};
> namespace literals {
> void operator "" _X(char const*);
> }
> }
> using B::literals::operator "" _X;
>
>
> // File main.c:
> #include "a.h"
> #include "b.h" // No conflict.
This is correct, but there is a still a difference when a third declaration for
the same name and parameter types exists in the global namespace. E.g.
given above declarations, the following additional declaration
(possibly unintended
included by either a.h or b.h):
whatever operator "" _X(char const*);
will be ill-formed. This problem does not occur via a using-directive.
I do not know whether this was meant here, but it would make sense.
- Daniel