Re: Namespaces like C++

2017-01-16 Thread Andrey via Digitalmars-d-learn

On Monday, 16 January 2017 at 19:17:57 UTC, Mike Parker wrote:
D namespaces generally follow the format [package 
names].moduleName.Type. So to have ui.Manager, then either the 
module, not the package, needs to be named 'ui', or you need to 
do the following:


// file ui/package.d
module ui;
public import ui.manager;

// file ui/manager.d
module ui.manager;
class Manager {}

Then you should be able to use ui.Manager and bypass the module 
name. The alternatives of static and named imports also work, 
but they need to be repeated in every module in which you want 
to use them.


Thanks! That did the trick!


Re: Namespaces like C++

2017-01-16 Thread Mike Parker via Digitalmars-d-learn

On Monday, 16 January 2017 at 18:02:09 UTC, Andrey wrote:
Hello, can I using namespaces like in C++, for example: 
ui::Widget or ui::Manager? I created ui/widget.d and 
ui/manager.d for implementation classes Widget and Manager, bun 
I can't import their correctly for using ui.Manager uiManager;


It should be:

ui.manager.Manager uiManager;

D namespaces generally follow the format [package 
names].moduleName.Type. So to have ui.Manager, then either the 
module, not the package, needs to be named 'ui', or you need to 
do the following:


// file ui/package.d
module ui;
public import ui.manager;

// file ui/manager.d
module ui.manager;
class Manager {}

Then you should be able to use ui.Manager and bypass the module 
name. The alternatives of static and named imports also work, but 
they need to be repeated in every module in which you want to use 
them.


Re: Namespaces like C++

2017-01-16 Thread rjframe via Digitalmars-d-learn
On Mon, 16 Jan 2017 18:02:09 +, Andrey wrote:

> Hello, can I using namespaces like in C++, for example: ui::Widget or
> ui::Manager? I created ui/widget.d and ui/manager.d for implementation
> classes Widget and Manager, bun I can't import their correctly for using
> ui.Manager uiManager;
> If it is impossible, then what is the best way to using namespaces in D?
> Should I naming my classes with prefix e.g. UIManager and UIWidget?

You can do either a static import or renamed import. The static import 
requires using the fully-qualified name; renamed imports let you set a 
local name for the module.

static import ui.widget;
ui.widget.SomeWidget w;

import mymanager = ui.manager;
mymanager.uiManager m;



For more information on modules see http://dlang.org/spec/module.html

--Ryan


Namespaces like C++

2017-01-16 Thread Andrey via Digitalmars-d-learn
Hello, can I using namespaces like in C++, for example: 
ui::Widget or ui::Manager? I created ui/widget.d and ui/manager.d 
for implementation classes Widget and Manager, bun I can't import 
their correctly for using ui.Manager uiManager;
If it is impossible, then what is the best way to using 
namespaces in D? Should I naming my classes with prefix e.g. 
UIManager and UIWidget?