www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Trouble with std.Variant

reply "ddos" <oggs gmx.at> writes:
struct Vec2
{
	float[2] vec;

	public float length()
	{
		return sqrt(vec[0]*vec[0]+vec[1]*vec[1]);
	}
}

int main(string[] argv)
{
	Vec2 test;
	Variant v = test;
     return 0;
}
Sep 18 2014
parent reply "ddos" <oggs gmx.at> writes:
The following code fails because Vec2.length() does not return 
int ... so Variant is only usable with types that do not have a 
method with name length() ?? i'm confused

On Thursday, 18 September 2014 at 21:03:47 UTC, ddos wrote:
 struct Vec2
 {
 	float[2] vec;

 	public float length()
 	{
 		return sqrt(vec[0]*vec[0]+vec[1]*vec[1]);
 	}
 }

 int main(string[] argv)
 {
 	Vec2 test;
 	Variant v = test;
     return 0;
 }
Sep 18 2014
parent reply =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 09/18/2014 02:06 PM, ddos wrote:
 The following code fails because Vec2.length() does not return int ...
 so Variant is only usable with types that do not have a method with name
 length() ?? i'm confused

 On Thursday, 18 September 2014 at 21:03:47 UTC, ddos wrote:
 struct Vec2
 {
     float[2] vec;

     public float length()
     {
         return sqrt(vec[0]*vec[0]+vec[1]*vec[1]);
     }
 }

 int main(string[] argv)
 {
     Vec2 test;
     Variant v = test;
     return 0;
 }
Compiles and runs without error with dmd git head, after adding the following two lines: ;) import std.math; import std.variant; Ali
Sep 18 2014
parent "Nicolas Sicard" <dransic gmail.com> writes:
On Thursday, 18 September 2014 at 21:14:55 UTC, Ali Çehreli wrote:
 On 09/18/2014 02:06 PM, ddos wrote:
 The following code fails because Vec2.length() does not return 
 int ...
 so Variant is only usable with types that do not have a method 
 with name
 length() ?? i'm confused

 On Thursday, 18 September 2014 at 21:03:47 UTC, ddos wrote:
 struct Vec2
 {
    float[2] vec;

    public float length()
    {
        return sqrt(vec[0]*vec[0]+vec[1]*vec[1]);
    }
 }

 int main(string[] argv)
 {
    Vec2 test;
    Variant v = test;
    return 0;
 }
Compiles and runs without error with dmd git head, after adding the following two lines: ;) import std.math; import std.variant; Ali
It shouldn't work in dmd git head. See Andrei's answer in https://issues.dlang.org/show_bug.cgi?id=5501
Sep 19 2014