Class attributes

Satoshi via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Oct 3 01:41:56 PDT 2016


On Sunday, 2 October 2016 at 17:22:57 UTC, Basile B. wrote:
> On Sunday, 2 October 2016 at 15:54:38 UTC, Satoshi wrote:
>> Hello,
>>
>> why
>> pure @safe nothrow @nogc struct Point {
>> }
>>
>> isn't same as
>>
>> struct Point {
>> pure: @safe: nothrow: @nogc:
>> }
>>
>> ??
>
> This is not specified but attributes aren't applied to the 
> scope created by the declaration. Which is a good thing, for 
> example with the visibility attributes it would be a problem, 
> imagine the following declarations:
>
> struct Foo(T)
> {
>     private struct Range // imagine that private as a inner 
> "private:"
>     {
>         void popFront(); // would be private !!
>         bool empty(); // would be private !!
>         T front(); // would be private !!
>     }
> }
>
> So this is really not something anyone would want.

But shared or abstract attribute can be applied to scope created 
by class so nothrow @safe @nogc or pure should be too.


It should follow same rules as in function declaration.

void test() @safe {
   void thisFunctionIsSafeToo() {

   }
}


More information about the Digitalmars-d-learn mailing list