Topic: [C++ Namespace] new rel_ops space stuffs things up...


Author: tonyn@tiac.net (Tony Nelson)
Date: 1998/05/22
Raw View
> using namespace std::rel_ops;

> namespace std{ using namespace rel_ops; }

I really don't understand why people are saying that these lines should be
equivalent.  The first one is a simple request for shorter names, while
the second one actually adds stuff to namespace std.  Seems that would
have to work, and is absolutely required for namespaces to be useful.
Namespaces are open.

But since I've never used namespaces, I could have been confused by
reading Stroustrup _Design and Evolutio of C++_
____________________________________________________________________
TonyN.:'                                              tonyn@tiac.net
      '     Looking for future Mac programming work.
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: fjh@cs.mu.OZ.AU (Fergus Henderson)
Date: 1998/05/25
Raw View
tonyn@tiac.net (Tony Nelson) writes:

>> using namespace std::rel_ops;
>
>> namespace std{ using namespace rel_ops; }
>
>I really don't understand why people are saying that these lines should be
>equivalent.  The first one is a simple request for shorter names,

Which is fine.

>while the second one actually adds stuff to namespace std.  Seems that would
>have to work, and is absolutely required for namespaces to be useful.
>Namespaces are open.

In the general case of an arbitrary namespace, I think the second example
does work, but in the specific case of "std", it does not -- users
are not allowed to add things to namespace std [17.4.3.1/1], except
for a few special cases.

--
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3        |     -- the last words of T. S. Garp.
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: loewis@informatik.hu-berlin.de (Martin v. Loewis)
Date: 1998/05/18
Raw View
msherman@magma.ca (Marc Sherman) writes:

> Can anyone shed any light on the following topic?  Does clause 3.4.2/3
> still exist as quoted below in the FDIS, and if so, does it imply the
> behaviour of CodeWarrior seen below w.r.t. Koenig lookup with templates
> in namespace std?

The clause still exists, and it indeed implies that

using namespace std::rel_ops;

will not result in Koenig lookup finding any of the rel_ops templates.

It is not clear why

namespace std{ using namespace rel_ops; }

should change the behaviour.

> Also, since 3.4.2/3 specifically states that /using-directive/s are
> the only thing ignored by Koenig lookup, would the code below work
> correclty if the /using-directive/ "using namespace std::rel_ops"
> were replaced by a /using-declaration/: "using
> std::rel_ops::operator>"?

Yes, that is the case.

> If so, why does the standard restrict Koenig lookup in this way?

Good question.

> It seems like an unnecessary restriction which makes std::rel_ops a
> real pain to use.

I agree. But then, std::rel_ops are apparently meant only for defining
the semantics of these operators in the standard, and not for a
library user.

Martin
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: msherman@magma.ca (Marc Sherman)
Date: 1998/05/16
Raw View
Can anyone shed any light on the following topic?  Does clause 3.4.2/3
still exist as quoted below in the FDIS, and if so, does it imply the
behaviour of CodeWarrior seen below w.r.t. Koenig lookup with templates
in namespace std?

Also, since 3.4.2/3 specifically states that /using-directive/s are
the only thing ignored by Koenig lookup, would the code below work
correclty if the /using-directive/ "using namespace std::rel_ops"
were replaced by a /using-declaration/: "using std::rel_ops::operator>"?
If so, why does the standard restrict Koenig lookup in this way?  It
seems like an unnecessary restriction which makes std::rel_ops a
real pain to use.

Thanks for any input,

- Marc

In article <hinnant-1505981957460001@port24.lightlink.com>,
Howard Hinnant <hinnant@_anti-spam_lightlink.com> wrote:
>I tried:
>
>#include <functional>
>#include <utility>
>
>  namespace A_ns
>  {
>    struct A
>    {
>      int a_int; // MSS: fixed from my original posting
>      bool operator<(const A& other) const { return a_int < other.a_int; }
>      bool operator==(const A& other) const { return a_int == other.a_int; }
>    };
>    using namespace std::rel_ops;
>  }
>  using A_ns::A;
>
>int main()
>{
>  std::greater<A> functor;
>  A a1;
>  A a2;
>  bool c = functor(a1, a2);
>}
>
>And I get:
>
>Error   : illegal operand
>functional line 154   bool operator () (const T& x, const T& y) const {
>return x > y; }
>
>That is:  There is no A > A.  However when I throw a:
>
>namespace std {using namespace rel_ops;}
>
>into the mix, the compiler swallows it.
>
>Is this standard?
>
>Well, the standard says this about koenig lookup and associations formed
>by using-directives:
>
> 3.4.2  Argument-dependent name lookup            [basic.lookup.koenig]
>
>3 When considering an associated namespace, the lookup is  the  same  as
>  the lookup performed when the associated namespace is used as a quali-
>  fier (_namespace.qual_) except that:
>
>  --Any using-directives in the associated namespace are ignored.
>
>Why is it this way?  I'm not sure.  If anyone has any explanations, I'm
>all ears.  Heck to tell you the truth, I don't have all the lookup rules
>down cold.  It's pretty twisty-turny stuff.  You proably have to write a
>standard compiler before you really understand the lookup rules!
>
>-Howard
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]