RE: C++ namespaces and 'using' question

2008-09-12 Thread Steve Huston
Hi Danushka,

> > To be pedantic if you have "using qpid::framing" then this tells
the
> > compier that any unqualified reference to "framing" is actually a
> > reference to "qpid::framing" so you can't remove the "framing::"
> > prefixes. ["using qpid::framing" == namespace framing = 
> qpid::framing"
> > in this context]
> >
> >   
> Andrew,
> 
> I dont think you can have "using qpid::framing" but "using
/namespace 
> /qpid::framing" as qpid::framing is not a symbol but a namespace.

Right.

After working a bit more on this, this is what I'd like to do:

- Not put in a blanket "using namespace qpid" - I agree that's too
far.

- Use, for example, "namespace framing = qpid::framing" as Andrew
mentions above. Then the existing framing::... works on both g++ and
MSVC.

Also, a guideline I'd like to see, and would like to hear more from
you all, is to always have some sort of namespace tag on classes that
are outside the namespace being worked on. For example, I was looking
at qpid/management/ManagementBroker.cpp - it refers to classes from
framing and broker as well. I'd like those to be explictly referred
to, such as:

namespace broker = qpid::broker;
namespace framing = qpid::framing;

...

framing::Buffer  buff;
...

Otherwise newbies like me have no clue where all these classes are
coming from. With the namespaces I have a good starting point for
where to look for more info on the class in question.

-Steve




Re: C++ namespaces and 'using' question

2008-09-11 Thread Danushka Menikkumbura



To be pedantic if you have "using qpid::framing" then this tells the
compier that any unqualified reference to "framing" is actually a
reference to "qpid::framing" so you can't remove the "framing::"
prefixes. ["using qpid::framing" == namespace framing = qpid::framing"
in this context]

  

Andrew,

I dont think you can have "using qpid::framing" but "using /namespace 
/qpid::framing" as qpid::framing is not a symbol but a namespace.


Danushka

--
Danushka Menikkumbura
Technical Lead, WSO2 Inc.

blog : http://danushka-menikkumbura.blogspot.com/

http://wso2.com/ - "The Open Source SOA Company"




Re: C++ namespaces and 'using' question

2008-09-11 Thread Andrew Stitcher

On Thu, 2008-09-11 at 08:20 -0400, Alan Conway wrote:
> ... 2. Removing all un-necessary namespace prefixes - if you have using
> namespace qpid::framing then you can just remove all the framing::
> prefixes.
> 

To be pedantic if you have "using qpid::framing" then this tells the
compier that any unqualified reference to "framing" is actually a
reference to "qpid::framing" so you can't remove the "framing::"
prefixes. ["using qpid::framing" == namespace framing = qpid::framing"
in this context]

Andrew




Re: C++ namespaces and 'using' question

2008-09-11 Thread Alan Conway
On Wed, 2008-09-10 at 20:45 -0400, Carl Trieloff wrote:
> Steve Huston wrote:
> > Hi,
> >
> > In working on the Windows port, I've come across a few places where
> > there's C++ using-directives such as:
> >
> > using namespace qpid::framing;
> >
> > ...
> >
> > int MyClass::Method (framing::Buffer &b)
> > ...
> >
> > g++ is ok with this construct, but Microsoft Visual C++ complains that
> > framing is unknown. Essentially, what VC wants is either:

g++ would not be ok with that unless you also have a 

using namespace qpid;

or MyClass is defined inside the qpid namespace.

I suspect the issue is that when you have:

namespace qpid { namespace broker { framing::Foo x; }}

gcc is checking all the surrounding namespaces (qpid::broker:: and
qpid::) but MSVC is checking only the exact current namespace
(qpid::broker::)

Not sure which is correct.

> >
> > using qpid::framing;
> >
> > Or
> >
> > using namespace qpid;
> 
> I think this one is the way to go and the correct per c++  -- andrew y/n?
> 
> using namespace qpid;
> 
> But we should make sure it works across all the complier options we support.
> 
> Carl.

That's correct but a bit draconian. I suspect the issue you describe can
be resolved by either:
 1. adding an extra using namespace qpid; which is easy.
 2. Removing all un-necessary namespace prefixes - if you have using
namespace qpid::framing then you can just remove all the framing::
prefixes.

I also don't want to get into a format war, but before we propose a rule
that causes a reformat of the entire codebase I'd like to be sure we
have identified the least painful fix. Adding extra using statements or
removing redundant prefixes is much easier than adding prefixes to every
un-prefixed identifier in every file that has such a using statement.

Cheers,
Alan.



Re: C++ namespaces and 'using' question

2008-09-10 Thread Andrew Stitcher
On Wed, 2008-09-10 at 12:13 -0400, Steve Huston wrote:
> Hi,
> 
> In working on the Windows port, I've come across a few places where
> there's C++ using-directives such as:
> 
> using namespace qpid::framing;

I believe the intent of this code is "using qpid::framing", and the code
author got a little confused!

> 
> ...
> 
> int MyClass::Method (framing::Buffer &b)
> ...
> 
> g++ is ok with this construct, but Microsoft Visual C++ complains that
> framing is unknown. Essentially, what VC wants is either:
> 
> using qpid::framing;
> 
> Or
> 
> using namespace qpid;
> 
> With code as is today, apparantly VC is trying to find "framing"
> within "qpid::framing", but not use "qpid::framing" itself.
> 
> I don't know C++ language and verse well enough to say what's right
> with any authority, but I believe MSVC is right here (and I think the
> Solaris compiler did the same thing). So far this sort of thing has
> been fixed by prepending qpid:: to the method signature (in the
> example above).

I'm not 100%, but I think you're correct that g++ is too lenient here -
the best place to test this is on the dinkumware website using the edg
compiler.

> ...
> How does this sound? I can put a jira for this as well, if it merits
> further discussion, but I don't want to get into a code format war.

On the whole I don't feel all that strongly about it, but I tend to
think that being more explicit is better so I'd prefer to see:

using qpid::framing;
using qpid::sys;
etc.

in the files that merit it, rather than a blanket:
using namespace qpid;

Andrew




Re: C++ namespaces and 'using' question

2008-09-10 Thread Carl Trieloff

Steve Huston wrote:

Hi,

In working on the Windows port, I've come across a few places where
there's C++ using-directives such as:

using namespace qpid::framing;

...

int MyClass::Method (framing::Buffer &b)
...

g++ is ok with this construct, but Microsoft Visual C++ complains that
framing is unknown. Essentially, what VC wants is either:

using qpid::framing;

Or

using namespace qpid;


I think this one is the way to go and the correct per c++  -- andrew y/n?

using namespace qpid;

But we should make sure it works across all the complier options we support.

Carl.