[Issue 6274] 'pure' for a whole struct definition

2022-08-15 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=6274

RazvanN  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 CC||razvan.nitu1...@gmail.com
 Resolution|--- |WONTFIX

--- Comment #3 from RazvanN  ---
Yes, you can use the `pure:` to obtain exactly what is requested. Closing as
WONTFIX.

--


[Issue 6274] 'pure' for a whole struct definition

2014-03-19 Thread d-bugmail
https://d.puremagic.com/issues/show_bug.cgi?id=6274


Infiltrator lt.infiltra...@gmail.com changed:

   What|Removed |Added

 CC||lt.infiltra...@gmail.com


--- Comment #2 from Infiltrator lt.infiltra...@gmail.com 2014-03-19 19:21:22 
PDT ---
Currently, instead of:

pure struct Foo { ... }

you can do:

struct Foo { pure: ... }


Is this acceptable?

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 6274] 'pure' for a whole struct definition

2011-08-12 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6274



--- Comment #1 from bearophile_h...@eml.cc 2011-08-12 12:44:00 PDT ---
There is something I don't fully understand. The following code compiles with
the improvements in DMD 2.055alpha/head, but it needs a pure or before
struct Map (here#1) or at the front() method of Map (here#2). If both are
removed it doesn't compile. So is the pure attribute for struct partially
working already?



@property bool empty(T)(in T[] a) pure nothrow {
return !a.length;
}

@property ref T front(T)(T[] a) pure nothrow {
assert(a.length);
return a[0];
}

void popFront(A)(ref A a) pure nothrow {
assert(a.length);
a = a[1 .. $];
}

pure struct Map(alias fun, R) { // here#1
R _input;

this(R input) nothrow pure {
_input = input;
}

@property bool empty() nothrow const pure {
return _input.empty;
}

@property auto ref front() nothrow const { // here#2
return fun(_input.front);
}

void popFront() nothrow pure {
_input.popFront();
}
}

template map(alias fun) {
auto map(R)(R range) {
return Map!(fun, R)(range);
}
}

int sqr(int x) pure nothrow { return x * x; }

pure nothrow int foo(int n) {
int total;
foreach (x; map!(sqr)([1, 2, 3, 4]))
total += x;
return total;
}

void main() {
assert(foo(10) == 30);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---