www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Class attributes

reply Satoshi <satoshi rikarin.org> writes:
Hello,

why
pure  safe nothrow  nogc struct Point {
}

isn't same as

struct Point {
pure:  safe: nothrow:  nogc:
}

??
Oct 02 2016
parent reply Basile B. <b2.temp gmx.com> writes:
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.
Oct 02 2016
parent Satoshi <satoshi gshost.eu> writes:
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() { } }
Oct 03 2016