Thread overview
[Issue 16532] Add "namespace" Keyword?
Sep 24, 2016
b2.temp@gmx.com
Oct 21, 2016
Jack
Oct 21, 2016
b2.temp@gmx.com
Oct 22, 2016
Mathias Lang
Jul 03, 2019
Mathias LANG
Mar 21, 2020
Basile-z
September 24, 2016
https://issues.dlang.org/show_bug.cgi?id=16532

--- Comment #1 from b2.temp@gmx.com ---
Instead of a struct you can use a template without parameter. The compatibility with C++ is not a valid argument because namespaces are supported: https://dlang.org/spec/cpp_interface.html#cpp-namespaces.

--
October 21, 2016
https://issues.dlang.org/show_bug.cgi?id=16532

--- Comment #2 from Jack <gyroheli@gmail.com> ---
Exactly, name spaces are supported but only through an extern. If I want to write D code with namespaces it isn't possible. Hence a lack of completeness.

You can't use a template without a parameter?

template Name()
{
    enum a = 2;
    enum b = 3;
}

writeln(Name.a, Name.b); // error Name has no property a or b

--
October 21, 2016
https://issues.dlang.org/show_bug.cgi?id=16532

b2.temp@gmx.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |b2.temp@gmx.com

--- Comment #3 from b2.temp@gmx.com ---
(In reply to Jack from comment #2)
> Exactly, name spaces are supported but only through an extern. If I want to write D code with namespaces it isn't possible. Hence a lack of completeness.
> 
> You can't use a template without a parameter?
> 
> template Name()
> {
>     enum a = 2;
>     enum b = 3;
> }
> 
> writeln(Name.a, Name.b); // error Name has no property a or b

You must alias it to create an instance.

alias name = Name!();

and in the code use this alias.

But you know, namespaces will never be added. D has modules, end of story. Ask on the news group and you'll see...You can even close this issue.

--
October 22, 2016
https://issues.dlang.org/show_bug.cgi?id=16532

Mathias Lang <mathias.lang@sociomantic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mathias.lang@sociomantic.co
                   |                            |m

--- Comment #4 from Mathias Lang <mathias.lang@sociomantic.com> ---
> Really namespaces already exist in D, just they are very crudly implemented by either meaning horrible to maintain with a bunch of extra module files or through the use of structs. Adding namespaces would just be for sanity so that code like above isn't possible and so that namespaces are treated as such. As well adding namespace keyword will also help port from C++ if there is any code that needs it. Just a thought for a small improvement.

First, this is an enhancement proposal, thus it should go through the DIP
process:
https://github.com/dlang/DIPs/

Second, namespacing in D are supported through module / packages.
You can choose to introduce extra namespacing without introducing new
modules/packages by using aggregates as already mentioned, but it sounds like
your real problem is trying to code with a C++ approach in D.

--
July 03, 2019
https://issues.dlang.org/show_bug.cgi?id=16532

Mathias LANG <pro.mathias.lang@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |pro.mathias.lang@gmail.com
         Resolution|---                         |WONTFIX

--
March 21, 2020
https://issues.dlang.org/show_bug.cgi?id=16532

Basile-z <b2.temp@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|b2.temp@gmx.com             |

--