Topic: proposal: void foo(namespace N);
Author: numerical.simulation@web.de (Markus Werle)
Date: Thu, 21 Nov 2002 14:48:28 +0000 (UTC) Raw View
Hi!
Maybe this has been proposed earlier, but searching
the archives for "namespace" and "argument" gives a lot
of hits with different topics, so I maybe overlooked any
possible earlier proposals.
While thinking about extending the flexibility
of a library I reconsidered the proposal of
a new keyword "namespace_of(typename)".
Maybe we can have a similar effect without a new
keyword, by simply(?) allowing the name of a namespace
to be given as argument to functions or templates
(A namespace is then treated as a type distinct from
all other types). Of couse this feature interacts well
with namespace_of, since then we can check whether
two types belong to the same namespace by testing
equivalence of types ...
namespace Test
{
void Execute(const std::string&);
}
void DoSomething(const std::string& s, namespace N)
{
using namespace N;
Execute(s, d);
}
template <namespace N> struct T
{
static void Go(const std::string& s) { N::Go(s); }
}
int main()
{
DoSomething("Hello", Test);
T<Test>::Go("Hello");
}
What do You think about this?
How much pain for compiler builders?
Markus
---
[ 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: remove.this.catalin.pitis@home.ro (Catalin Pitis)
Date: Thu, 21 Nov 2002 17:01:13 +0000 (UTC) Raw View
I gave an alternative solution, using existing language facilities.
In article <ariimv$rkd$1@nets3.rz.RWTH-Aachen.DE>,
numerical.simulation@web.de says...
> Hi!
>
> Maybe this has been proposed earlier, but searching
> the archives for "namespace" and "argument" gives a lot
> of hits with different topics, so I maybe overlooked any
> possible earlier proposals.
>
> While thinking about extending the flexibility
> of a library I reconsidered the proposal of
> a new keyword "namespace_of(typename)".
>
> Maybe we can have a similar effect without a new
> keyword, by simply(?) allowing the name of a namespace
> to be given as argument to functions or templates
> (A namespace is then treated as a type distinct from
> all other types). Of couse this feature interacts well
> with namespace_of, since then we can check whether
> two types belong to the same namespace by testing
> equivalence of types ...
>
>
> namespace Test
> {
> void Execute(const std::string&);
> }
struct Test
{
static void Execute(const std::string&);
};
>
>
> void DoSomething(const std::string& s, namespace N)
> {
> using namespace N;
> Execute(s, d);
> }
>
template <typename N>
void DoSomething(const std::string& s)
{
N::Execute(s);
}
> template <namespace N> struct T
> {
> static void Go(const std::string& s) { N::Go(s); }
> }
// I think you mean N::Execute( s)
template <typename N> struct T
{
static void Go(const std::string& s) { N::Execute(s); }
};
> int main()
> {
> DoSomething("Hello", Test);
> T<Test>::Go("Hello");
> }
>
int main()
{
DoSomething< Test>( "Hello");
T<Test>::Go( "Hello");
}
>
> What do You think about this?
> How much pain for compiler builders?
>
Think in the existing terms: a class can act like a namespace, under
certain limits...
>
> Markus
Catalin Pitis
---
[ 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: gdr@integrable-solutions.net (Gabriel Dos Reis)
Date: Thu, 21 Nov 2002 18:12:03 +0000 (UTC) Raw View
numerical.simulation@web.de (Markus Werle) writes:
| template <namespace N> struct T
I miss this construct in my own library code, but the form of
namespace as function argument isn't something I would support :-).
I was told that that extension was proposed in the past (before the
standard was frozen) but the proposal was poorly worded...
Simulating namespace-as-template-argument through use of static members
can be very painful and not scalable. I would appreciate in-depth
discussions about the pros and cons of this putative extension.
[...]
| What do You think about this?
At first sight I would say it would complicate name lookup rules
(they aren't sufficiently complex, do they? :-) and probably exported
templates also (although I'm not sure it would add any /significant/
complexity).
--
Gabriel Dos Reis, gdr@integrable-solutions.net
---
[ 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: petebecker@acm.org (Pete Becker)
Date: Thu, 21 Nov 2002 23:33:33 +0000 (UTC) Raw View
Gabriel Dos Reis wrote:
>
> numerical.simulation@web.de (Markus Werle) writes:
>
> | template <namespace N> struct T
>
> I miss this construct in my own library code, but the form of
> namespace as function argument isn't something I would support :-).
>
> I was told that that extension was proposed in the past (before the
> standard was frozen) but the proposal was poorly worded...
>
My recollection is that it was too scary. We were just beginning to
understand the implications of templates with values and types as
parameters, and namespaces were mental overload. That was my reaction,
anyway, and I was happy to see the idea disappear. We're still
struggling with name lookup rules in templates, and while I'm not scared
of the idea any more, I still think that namespaces as template
parameters are too complicated to take on now.
--
Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
---
[ 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 ]