February 28, 2014 Re: Write variable from other function | ||||
---|---|---|---|---|
| ||||
Posted in reply to Suliman |
> bool isConfigExist()
>
> {
> configpath = exePath() ~ "config.txt";
> if (exists(configpath))
> {
> return true;
> }
>
> else
> return false;
>
> }
>
> Now function return only bool and I need to make it's universal
> to get text also
Probably not very good idea from me, I understand that I was wrong thinking!
|
February 28, 2014 Re: Write variable from other function | ||||
---|---|---|---|---|
| ||||
Posted in reply to Suliman | On Friday, 28 February 2014 at 18:18:15 UTC, Suliman wrote:
> Probably not very good idea from me, I understand that I was wrong thinking!
In case you really-really-really want it, such behavior can be achieved via std.typecons.Tuple :
import std.typecons;
auto foo()
{
return tuple(true, "text");
}
void main()
{
auto ret_val = foo();
assert(ret_val[1] == "text");
}
|
February 28, 2014 Re: Write variable from other function | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dicebot | On 02/28/2014 06:42 AM, Dicebot wrote: > You want static variables, either in form of global variables > (discouraged) or static class fields: Luckily, there is no global namespace in D. So, when it makes sense module-level global variables are fine as well. Ali |
Copyright © 1999-2021 by the D Language Foundation