www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How auto convert Variant to required function arguments?

reply Marcone <marcone email.com> writes:
How auto convert Variant to required function arguments?
Oct 08 2020
parent reply Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= <aferust gmail.com> writes:
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)); }
Oct 09 2020
parent reply Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= <aferust gmail.com> writes:
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.
Oct 09 2020
parent Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= <aferust gmail.com> writes:
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*
Oct 09 2020