Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
June 18, 2010 [phobos] Is this a bug? | ||||
---|---|---|---|---|
| ||||
Seems like it is, but I haven't made enough sense of the Variant code to be sure: import std.variant; import std.typecons; struct Val { Variant v; Object o; } void set(T...)( T vals ) { alias Tuple!(Val) Wrap; Wrap wrap; Variant data; wrap.field = vals; data = wrap; } void main() { Val val; set( val ); } $ dmd test /usr/local/include/d/std/variant.d(509): Error: template std.typecons.Tuple!(Val).Tuple.__ctor(U...) if (U.length == Types.length) does not match any function template declaration /usr/local/include/d/std/variant.d(509): Error: template std.typecons.Tuple!(Val).Tuple.__ctor(U...) if (U.length == Types.length) cannot deduce template function from argument types !()() $ It's also weird that if I assign a value containing a variant plus more stuff to a variant it seems to think it can hold it. In my real code (std.concurrency) I test the value size before assigning, but the test passes for some reason. |
June 18, 2010 [phobos] Is this a bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean Kelly | More compact: import std.variant; import std.typecons; struct Val { Variant v; Object o; } void main() { alias Tuple!(Val) Wrap; Wrap wrap; Variant data; Val val; wrap.field[0] = val; data = wrap; } I think it's simply a bug with the static checking in the opAssign for Variant. It should reject the value as too large, but instead it accepts it and explodes. When I pass a Val* the code compiles fine. |
June 18, 2010 [phobos] Is this a bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean Kelly | Found it. I forgot you can't new a Tuple. This breaks: import std.typecons; void main() { alias Tuple!(int) Wrap; auto p = new Wrap; } I'll see about fixing Tuple instead of changing Variant. |
June 18, 2010 [phobos] Is this a bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean Kelly | On Jun 18, 2010, at 8:51 PM, Sean Kelly wrote:
> Found it. I forgot you can't new a Tuple. This breaks:
>
> import std.typecons;
>
> void main()
> {
> alias Tuple!(int) Wrap;
> auto p = new Wrap;
> }
>
> I'll see about fixing Tuple instead of changing Variant.
It's because Tuple doesn't have a default ctor. Since this clearly causes problems with generic code, I think it's worth adding one. I'll sit on the checkin until tomorrow. Scream and yell if you think it's a terrible idea.
|
August 26, 2010 [phobos] Is this a bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean Kelly | The code should work. I submitted a fix a while ago that allows Variant to hold types of any size (internally it uses pointers and dynamic allocation).
Did you submit this to bugzilla?
Andrei
On 6/18/10 20:45 PDT, Sean Kelly wrote:
> More compact:
>
> import std.variant;
> import std.typecons;
>
> struct Val
> {
> Variant v;
> Object o;
> }
>
> void main()
> {
> alias Tuple!(Val) Wrap;
> Wrap wrap;
> Variant data;
> Val val;
>
> wrap.field[0] = val;
> data = wrap;
> }
>
> I think it's simply a bug with the static checking in the opAssign for Variant. It should reject the value as too large, but instead it accepts it and explodes. When I pass a Val* the code compiles fine.
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
|
Copyright © 1999-2021 by the D Language Foundation