Code-File structure
Artur Skawina
art.08.09 at gmail.com
Thu Jun 14 13:53:42 PDT 2012
On 06/14/12 22:03, Pragma Tix wrote:
> Am 14.06.2012 20:01, schrieb Artur Skawina:
>> On 06/14/12 19:26, Pragma Tix wrote:
>>> Am 13.06.2012 03:56, schrieb Nathan M. Swan:
>>>> You cannot put multiple modules in a file like C++ namespaces.
>>>
>>> A nice trick in D for creating local namespaces that combine items from several modules under one name is to use a mixin template.
>>>
>>> mixin template StdLib()
>>> {
>>> import std.string;
>>> import std.stdio;
>>> }
>>>
>>> mixin StdLib!() stdlib;
>>
>> The 'mixin' part is not necessary:
>>
>> template StdLib() {
>> import std.string;
>> import std.stdio;
>> }
>> alias StdLib!() stdlib;
>>
>> but you don't even need a template:
>>
>> struct stdlib { import std.string, std.stdio; }
>>
>>
>> artur
>
> That's pretty cool. thanks. Is this struct {import ...}feature documented.. somewhere ?
It's how imports work; a struct creates a named scope, so does a template.
"Scoped" imports are documented: http://dlang.org/module.html
artur
More information about the Digitalmars-d-learn
mailing list