std.boxer vs Any

Daniel Keep daniel.keep.lists at gmail.com
Wed Oct 10 02:56:14 PDT 2007



Aarti_pl wrote:
> ...
> 
> 1. It looks that opAssign is not very well suited for containers of this
> type. The problem is that it disallows to put Variant into Variant (what
> is sometimes very useful), as operator will not start work at all, but
> just pointers to/values of containers will be replaced. Because of that
> it is necessary to have free function, static opCall or use (ugly)
> opAssign() function explicitly to achieve desired effect.

To be fair, the "correct" way to do this isn't entirely clear-cut.  I
wrestled with this exact problem for quite a while before deciding that
the use-case of putting a Variant inside of a Variant would be fairly
borderline, and that being able to pass values around would be more useful.

However, I agree that the workaround is ugly.  Perhaps an explicit set
member that doesn't do the coercion?

> import variant; // I hacked Tango version a little bit
>         // to work with Phobos

You realise that the original Variant ran unmodified in both Phobos and
Tango, right?  And was developed first for Phobos and then ported?  And
that Tango actually fails on a few of the unittests?

And had that exact same fully-qualified module name?

:P

> ...
>
> For reference: http://dsource.org/projects/tango/forums/topic/12

I must admit that I'd forgotten that thread was even there; I don't
think I saw the replies after Pragma's reply to my post.

> 2. There is no isEmpty() function (same problem as in Box). I think that
> clear() would be nice also, but maybe not so useful.

The rationale was that you should be able to do this:

Variant v;
if( v.isA!(void) ) { ... }

With the implication that if nothing's stored in a Variant, the storage
type is void.  However, you're probably right; an actual isEmpty would
probably be easier to use.

As for clearing it...

v = Variant.init;

Not sure if you'd gain much by having a clear member.

> 3. Automatic conversion of arguments to variadic argument functions into
> Variant is not possible (Boxer has it.)

I got the idea from Pragma's post on the Tango forums, but the reason I
wrote it was because I was doing a configuration library thing, and
needed dynamically typed storage (wow; that sounds familiar :P).

The reason why it doesn't do the variadic trick that std.boxer does is
because I didn't need it, and because I wasn't sure how to make it work
in both Phobos and Tango at the same time.  It was basically a can of
worms I didn't need to open, and didn't really want to.

It's not that it's not possible, it's just that I never implemented it.

> 4. toUtf8 doesn't work in Tango.

I didn't actually do the integration of Variant into Tango (I believe
Sean did,) but from what I can tell they removed the toUtf8
functionality so it wouldn't depend on all the formatting stuff the
original pulled in.

The original Variant did the toString/toUtf8 trick of formatting its
contents just fine, so don't blame me! :)

> ------
> 
> 'B' part of your question:
> Yes, it is possible that I change .as() to something else (get!()?). But
> I am thinking also about dropping Any in favor of Box or Variant.
> 
> Variant would be my choose if only it fix reasonably above mentioned
> problems.
>
> Best Regards
> Marcin Kuszczak
> (aarti_pl - www.zapytajmnie.com)

I pretty much agree with what you said, with the exception of putting
Variants inside Variants.  I just can't think of a use-case for that
where using `var.set(some_other_var)` wouldn't be acceptable.

I'm basically swamped at the moment, and I'm pretty much booked out
after my current work is done (yes, Kris, I'm getting to the cairo
bindings!).  That said, the source is up at
<http://www.prowiki.org/wiki4d/wiki.cgi?DanielKeep/Variant>, so if you
want to contribute isEmpty/clear and the variadic stuff, feel free. :)

	-- Daniel



More information about the Digitalmars-d mailing list