Thread overview | ||||||
---|---|---|---|---|---|---|
|
October 09, 2020 How auto convert Variant to required function arguments? | ||||
---|---|---|---|---|
| ||||
How auto convert Variant to required function arguments? |
October 09, 2020 Re: How auto convert Variant to required function arguments? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marcone | On Friday, 9 October 2020 at 00:19:20 UTC, Marcone wrote:
> How auto convert Variant to required function arguments?
import std.variant;
import std.stdio;
Variant a;
int mul2(Variant b){
int c = *b.peek!(int);
return 2*c;
}
int mul3(int b){
return 3*b;
}
void main()
{
a = 5;
writeln(mul2(a));
Variant b = 3;
writeln(mul3(*b.peek!int));
}
|
October 09, 2020 Re: How auto convert Variant to required function arguments? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ferhat Kurtulmuş | On Friday, 9 October 2020 at 15:49:31 UTC, Ferhat Kurtulmuş wrote: > On Friday, 9 October 2020 at 00:19:20 UTC, Marcone wrote: >> How auto convert Variant to required function arguments? > > > import std.variant; > import std.stdio; > > Variant a; > > int mul2(Variant b){ > int c = *b.peek!(int); > return 2*c; > } > > int mul3(int b){ > return 3*b; > } > > void main() > { > a = 5; > writeln(mul2(a)); > > Variant b = 3; > writeln(mul3(*b.peek!int)); > } Uh, probably this is not what you want. I found this thread: https://forum.dlang.org/thread/ebylgcrslkelgrvntjws@forum.dlang.org You man need to use Algebraic. |
October 09, 2020 Re: How auto convert Variant to required function arguments? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ferhat Kurtulmuş | On Friday, 9 October 2020 at 16:10:03 UTC, Ferhat Kurtulmuş wrote:
> On Friday, 9 October 2020 at 15:49:31 UTC, Ferhat Kurtulmuş wrote:
>> On Friday, 9 October 2020 at 00:19:20 UTC, Marcone wrote:
>>> How auto convert Variant to required function arguments?
>>
>>
>> import std.variant;
>> import std.stdio;
>>
>> Variant a;
>>
>> int mul2(Variant b){
>> int c = *b.peek!(int);
>> return 2*c;
>> }
>>
>> int mul3(int b){
>> return 3*b;
>> }
>>
>> void main()
>> {
>> a = 5;
>> writeln(mul2(a));
>>
>> Variant b = 3;
>> writeln(mul3(*b.peek!int));
>> }
> Uh, probably this is not what you want. I found this thread: https://forum.dlang.org/thread/ebylgcrslkelgrvntjws@forum.dlang.org
>
> You man need to use Algebraic.
may*
|
Copyright © 1999-2021 by the D Language Foundation