Topic: Definition namespaces (was: template block proposal to simplify out of class definitions)
Author: nesotto@cs.auc.dk ("THORSTEN OTTOSEN")
Date: Sat, 1 Feb 2003 00:29:57 +0000 (UTC) Raw View
"KIM Seungbeom" <musiphil@bawi.org> wrote in message
news:3E372833.91C3F193@bawi.org...
> "David B. Held" wrote:
> >
> > I actually like the idea of using namespace to create what amounts
> > to a type of "with clause". It's like James Kanze's suggestion, only
> > without introducing a new keyword. And logically, 'namespace'
> > seems most appropriate in this context anyway. However, I would
> > rearrange the syntax, so it appears like this:
> >
> > namespace class Foo { /* ... */ }
> >
> > namespace template <typename T> class Goo { /* ... */ }
>
> I'm not sure if it would be really good to use the keyword 'namespace'
> here. A class constitutes a 'name space' (in the general meaning), but
> a class is not a 'namespace' (in the C++ specific meaning). Wouldn't
> it be confusing to use the same word for two different things?
>
why? You can also use typename and class for many things:
template< class C, template <class,class> class C2 >
class X
{
};
template< typename C, template<typename,typename> class C2>
class X
{
typename C::member ...;
};
Anyway, I like the use of re-using the namespace whenever a namespace is
reopened
for definition purposes. Maybe it should also be possible to make a
templated "normal" namespace
such that template functions can be easier forward declarared and
implemented:
template< typename T, typename V >
namespace boost
{
}
or
namespace template< typename T, typename V >
boost
{
}
or
namespace boost
{
template< typename T, typename V >
{
...
}
template< typename T >
{
...
}
}
regards
Thorten
---
[ 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://www.jamesd.demon.co.uk/csc/faq.html ]
Author: nesotto@cs.auc.dk ("THORSTEN OTTOSEN")
Date: Sat, 1 Feb 2003 00:33:24 +0000 (UTC) Raw View
"KIM Seungbeom" <musiphil@bawi.org> wrote in message
news:3E38AD23.CD8B12EF@bawi.org...
> "David B. Held" wrote:
> >
> > "KIM Seungbeom" <musiphil@bawi.org> wrote in message
> > news:3E372833.91C3F193@bawi.org...
> > > [...]
> > > I'm not sure if it would be really good to use the keyword 'namespace'
> > > here. A class constitutes a 'name space' (in the general meaning), but
> > > a class is not a 'namespace' (in the C++ specific meaning). Wouldn't
> > > it be confusing to use the same word for two different things?
> >
> > You mean like 'static'? Or 'virtual'? Or 'class'? I personally don't
think
> > it would be confusing because the name of the namespace is special.
> > And I can't think of another keyword that is as appropriate. Nor do I
> > think it appropriate to introduce another keyword for this particular
> > feature.
>
> Do we really have to use a keyword for this?
doesn't the example below use a keyword?
> Magnus Lidbom suggested suggested a syntax that use one:
>
> class Foo::
> {
> int f() const
> {
> //...
> }
> };
did you mean
Foo::
{
...
}
?
regards
Thorsten
---
[ 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://www.jamesd.demon.co.uk/csc/faq.html ]
Author: dheld@codelogicconsulting.com ("David B. Held")
Date: Sat, 1 Feb 2003 00:36:24 +0000 (UTC) Raw View
"KIM Seungbeom" <musiphil@bawi.org> wrote in message
news:3E3A9FEE.9D544CE0@bawi.org...
> [...]
> Okay, I admit that I'm not advocating that syntax in particular,
> but it was an example of not using a keyword.. We could drop
> the terminating semicolon, or devise a whatever better syntax.
Feel free to do so. ;)
> The fact is that I still don't see why many folks here say that
> classes are namespaces. A class constitutes a scope, and so
> does a namespace. A class scope and a namespace scope
> are different.
Just as a namespace and a definition namespace or a template
parameter namespace are different and have different syntax
(but a syntactic similarity appropriate to their semantic similarity,
in my opinion).
> The standard makes it clear what a 'namespace' means, and I
> don't think it is what the people here is talking about.
Nobody is proposing to extend the notion of 'namespace' to a
definition namespace. Rather, the idea is to create an entirely
new concept based a little on class scope and a little on
namespaces, and combine the two syntactically and semantically,
which is why I think the current syntax is most appropriate.
Dave
P.S. I think I must argue for this form for template classes:
namespace template <typename ...> class Foo
{
}
It may seem a little longer, but A) it makes all namespace-type
declarations similar: they all begin with 'namespace' followed
by some token sequence, B) I think template parameter
namespaces should look like class namespaces such that
'template' follows 'namespace', and that they should not be
combinable with an actual namespace name, such as:
template <...>
namespace N1
{
}
becomes
namespace template <...> N1
{
}
Here, it makes N1 look like a "template namespace" which
doesn't make much sense. Namespaces are not types. This
way, the following is not ambiguous for "template parameter
namespace in the global namespace" or "template parameter
namespace in an anonymous namespace".
template <...>
namespace
{
}
This way makes it clearer:
namespace template <...>
{
}
namespace
{
namespace template <...>
{
}
}
---
[ 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://www.jamesd.demon.co.uk/csc/faq.html ]
Author: dheld@codelogicconsulting.com ("David B. Held")
Date: Wed, 29 Jan 2003 20:03:47 +0000 (UTC) Raw View
"KIM Seungbeom" <musiphil@bawi.org> wrote in message
news:3E372833.91C3F193@bawi.org...
> [...]
> I'm not sure if it would be really good to use the keyword 'namespace'
> here. A class constitutes a 'name space' (in the general meaning), but
> a class is not a 'namespace' (in the C++ specific meaning). Wouldn't
> it be confusing to use the same word for two different things?
You mean like 'static'? Or 'virtual'? Or 'class'? I personally don't
think
it would be confusing because the name of the namespace is special.
And I can't think of another keyword that is as appropriate. Nor do I
think it appropriate to introduce another keyword for this particular
feature.
What would be problematic is if people did indeed try to use it like
a namespace:
class Foo
{
void bar();
static int x;
};
namespace class Foo
{
void bar() { ... } // Ok
int x; // Ok
int y; // Trying to declare a namespace level variable inside class
// scope is not legal now, nor should be under this proposal
void baz() { ... } // Same for namespace level functions
int ::z; // Should this be allowed? Put the name in global scope?
void ::baw() { ... }
class Z { ... }; // Namespace level class, or nested class? Should
// not be legal
}
Dave
---
[ 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://www.jamesd.demon.co.uk/csc/faq.html ]
Author: m.collett@auckland.ac.nz (Matthew Collett)
Date: Thu, 30 Jan 2003 21:03:11 +0000 (UTC) Raw View
In article <3E38AD23.CD8B12EF@bawi.org>,
musiphil@bawi.org (KIM Seungbeom) wrote:
> Magnus Lidbom suggested suggested a syntax that use one:
>
> class Foo::
> {
> int f() const
> {
> //...
> }
> };
Consistency (or do I mean orthogonality?) suggests that you could then
use namespace Bar:: in similar fashion, to open a namespace for
implementation only:
namespace Bar::
{
// Only definitions of previously declared names allowed
int g() //Error unless Bar::g has already been declared
{
//...
}
}
(I don't think you want the final semicolon, in either case.)
Best wishes,
Matthew Collett
--
Those who assert that the mathematical sciences have nothing to say
about the good or the beautiful are mistaken. -- Aristotle
---
[ 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://www.jamesd.demon.co.uk/csc/faq.html ]
Author: dheld@codelogicconsulting.com ("David B. Held")
Date: Thu, 30 Jan 2003 21:03:28 +0000 (UTC) Raw View
"KIM Seungbeom" <musiphil@bawi.org> wrote in message
news:3E38AD23.CD8B12EF@bawi.org...
> [...]
> Do we really have to use a keyword for this?
> Magnus Lidbom suggested suggested a syntax that use one:
>
> class Foo::
> {
> int f() const
> {
> //...
> }
> };
This looks too much like a declaration for my tastes. It's not
sufficiently different from a declaration to indicate to me that it's
only a definition namespace, and not a full reopening of the class.
Whereas:
namespace class Foo
{
int f() const
{
// ...
}
}
tells me that this is fundamentally different from reopening a
class, which is exactly the case. Also, note the peculiarity with
the terminating semicolon. In your example, that comes from
class declaration syntax, because one can put an identifier after
the declaration. Can they also put an identifier after the
definition namespace? I.e.:
class Foo::
{
// ...
} foo;
;> Note that 'namespace' has no such peculiarity.
Dave
---
[ 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://www.jamesd.demon.co.uk/csc/faq.html ]
Author: cpdaniel@nospam.mvps.org ("Carl Daniel")
Date: Wed, 22 Jan 2003 18:06:11 +0000 (UTC) Raw View
"David Abrahams" <dave@boost-consulting.com> wrote in message
news:ulm1d6e51.fsf@boost-consulting.com...
> struct X
> {
> // copying your code here:
> int
> f( int y )
> {
> // ...
> }
> };
>
> namespace Y
> {
> // copying your code here:
> int
> f( int y )
> {
> // ...
> }
> }
>
> Two non-global functions.
You'll find that very analogy as part of the motivation for the proposed
change in the paper I'm writing...
Once a few more eyes have looked over the paper, I'll put it up on a web
server & post the URL here so yet others can read & comment on it.
-cd
---
[ 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://www.jamesd.demon.co.uk/csc/faq.html ]
Author: kanze@gabi-soft.de (James Kanze)
Date: Tue, 21 Jan 2003 19:13:28 +0000 (UTC) Raw View
dave@boost-consulting.com (David Abrahams) wrote in message
news:<uadhzik1g.fsf@boost-consulting.com>...
> dheld@codelogicconsulting.com ("David B. Held") writes:
> > I actually like the idea of using namespace to create what amounts
> > to a type of "with clause". It's like James Kanze's suggestion,
> > only without introducing a new keyword. And logically, 'namespace'
> > seems most appropriate in this context anyway. However, I would
> > rearrange the syntax, so it appears like this:
> <snip>
> > This is really helpful for the nested types, as current C++ requires
> > the following syntax:
> > template <typename T>
> > template <typename U>
> > typename Goo::nested baz(U t) { ... }
> > template <typename T>
> > template <typename U>
> > typename Goo::X<T> biz(T t, U u) { ... }
> > When Goo and X are long names, this syntax makes it harder to find
> > the name of the function. When the template parameter list is much
> > longer, the return type alone can take an entire line.
The return type is always on a line by itself anyway, isn't it? (This
is an old habit from C: "grep ^functionName" finds the function
definition, and only the function definition.)
> I agree. Repeated boilerplate is bad for maintainability and
> usability, but so is sticking implementation details in the interface
> description. It would be a lot better if C++ didn't make us choose
> between them. "Someone" should write up a proposal for the next
> version of the standard.
I sort of agree as well. But in all fairness, it is worth pointing out
the counter-argument. Today, when I see:
int
f( int y )
{
// ...
}
I know that it is a global function. With this proposal, I have to find
the nearest enclosing block to know whether it is a global function or a
class member. (Note that this argument can also be used in favor of
static functions rather than anonymous namespaces.)
I still think that the advantages outweigh the disadvantages, especially
the day you decide to add an allocator template parameter (with an
appropriate default, of course) to your templated container.
--
James Kanze mailto:jkanze@caicheuvreux.com
Conseils en informatique orient e objet/
Beratung in objektorientierter Datenverarbeitung
---
[ 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://www.jamesd.demon.co.uk/csc/faq.html ]
Author: nesotto@cs.auc.dk ("THORSTEN OTTOSEN")
Date: Tue, 21 Jan 2003 23:54:16 +0000 (UTC) Raw View
""Carl Daniel"" <cpdaniel@nospam.mvps.org> wrote in message
news:_20X9.1181$rw6.40260727@newssvr21.news.prodigy.com...
> "David Abrahams" <dave@boost-consulting.com> wrote in message
> news:uadhzik1g.fsf@boost-consulting.com...
> > description. It would be a lot better if C++ didn't make us choose
> > between them. "Someone" should write up a proposal for the next
> > version of the standard.
>
> Yes, "Someone" should write up a proposal!
>
> I'm willing to be that someone, if the originators of this thread don't
> mind.
Great :-) And I don't mind. I'm pretty sure you're a better person for the
job than I
given that I have only owned the standard for a month.
best regards
Thorsten
---
[ 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://www.jamesd.demon.co.uk/csc/faq.html ]
Author: dheld@codelogicconsulting.com ("David B. Held")
Date: Mon, 20 Jan 2003 18:33:54 +0000 (UTC) Raw View
""Jacques Lolieux"" <jlolieux@btinternet.com> wrote in message
news:b0egh3$t8q$1@venus.btinternet.com...
> [...]
> Why not simply reopen the class as a namespace since a class is already
> a kind of namespace:
>
> template<class T> class A {
> void f();
> };
> template<class T> namespace A {
> void f() { ... }
> }
What I don't like about this syntax is that it makes it look like you have a
"templated namespace", which doesn't make any sense to me. It seems
like you should get a new "namespace instance" when the template is
instantiated. What you are really doing is specifying the namespace for
a template class, which is why I favor putting namespace first.
> class B {
> void g();
> };
> namespace B {
> void g() { }
> }
I think this makes it harder to tell if B is the name of a real namespace or
a class, especially since these will probably occur in different files.
Adding
class or struct disambiguates it for readers, and does not change the
meaning of existing code. It also highlights the fact that it isn't just a
namespace, since it would have slightly different properties.
Dave
---
[ 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://www.jamesd.demon.co.uk/csc/faq.html ]
Author: cpdaniel@nospam.mvps.org ("Carl Daniel")
Date: Tue, 21 Jan 2003 00:03:38 +0000 (UTC) Raw View
"David Abrahams" <dave@boost-consulting.com> wrote in message
news:uadhzik1g.fsf@boost-consulting.com...
> description. It would be a lot better if C++ didn't make us choose
> between them. "Someone" should write up a proposal for the next
> version of the standard.
Yes, "Someone" should write up a proposal!
I'm willing to be that someone, if the originators of this thread don't
mind. Once a reasonably thorough proposal document was prepared, I'd
hope to get a member of the committee to take this proposal "under their
wing". On the surface (at least), this seems like a worthwhile addition
to the language: it could be added in a way that breaks no existing
code, while offering a significant improvement in readability and
maintenance of C++ code. On the surface, it seems like a change that
would be straightforward for compiler writers to implement, as well.
-cd
---
[ 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://www.jamesd.demon.co.uk/csc/faq.html ]
Author: dheld@codelogicconsulting.com ("David B. Held")
Date: Fri, 17 Jan 2003 00:25:02 +0000 (UTC) Raw View
"Uwe Schnitker" <schnitker@sigma-c.com> wrote in message
news:aec458c5.0301160034.49c9d15d@posting.google.com...
> [...]
> <IRONY>
> Given that keyword overloading is one of the primary reuse
> mechanisms in C++, we might want to make that:
>
> template<typename T1, template <typename T2> class T3>
> namespace
> {
> template<typename T4, typename T5, typename T6>
> void
> Foo::bar(T4 arg1, T5 arg2, T6 arg3){
>
> //stuff
> }
> }
> [...]
> </IRONY>
> [...]
I actually like the idea of using namespace to create what amounts
to a type of "with clause". It's like James Kanze's suggestion, only
without introducing a new keyword. And logically, 'namespace'
seems most appropriate in this context anyway. However, I would
rearrange the syntax, so it appears like this:
class Foo
{
public:
void bar(int x);
template <typename T>
void baz(T t);
};
template <typename T>
class Goo
{
public:
template <typename U>
struct X { ... };
typedef int nested;
void bar(int x);
template <typename U>
nested baz(U t);
template <typename U>
X<T> biz(T t, U u);
};
namespace class Foo
{
void bar(int x)
{ ... }
template <typename T>
void baz(T t)
{ ... }
}
namespace template <typename T> class Goo
{
void bar(int x) { ... }
namespace template <typename U>
{
nested baz(U t) { ... }
X<T> biz(T t, U u) { ... }
}
}
This is really helpful for the nested types, as current C++ requires the
following syntax:
template <typename T>
template <typename U>
typename Goo::nested baz(U t) { ... }
template <typename T>
template <typename U>
typename Goo::X<T> biz(T t, U u) { ... }
When Goo and X are long names, this syntax makes it harder to find the
name of the function. When the template parameter list is much longer,
the return type alone can take an entire line.
Dave
---
[ 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://www.jamesd.demon.co.uk/csc/faq.html ]