On Thursday, 24 March 2016 at 06:54:25 UTC, Alex wrote:
Hi everybody,
doing some optimization on my code, I faced some strange
question:
how to save a iota result in a class member?
Say I have
class A
{
??? member;
auto testIter4()
{
return iota(0,5);
}
}
void main()
{
A a = new A();
a.member = testIter4();
}
how would I declare the member?
Yeah this is one of the downsides of voldermort types. In these
cases typeof and ReturnType are your friend. It often takes me a
couple of tries to get it right, but the following seems to work:
import std.traits : ReturnType;
import std.range : iota;
class A
{
ReturnType!(A.testIter4) member;
auto testIter4()
{
return iota(0,5);
}
}
void main()
{
A a = new A();
a.member = a.testIter4();
}