std.boxer vs Any

Aarti_pl aarti at interia.pl
Wed Oct 10 04:04:22 PDT 2007


Daniel Keep pisze:
> 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?

I would probably choose now free function only. It's not that much of 
benefit in having opAssign. Main drawback is that you have to decide in 
advance if you will need Variant in Variant functionality. If you change 
your mind, you will probably need to review whole source code and 
replace everything to use .set() instead of assignment.

Having both (free function and opAssign) is also not very nice.

I wrote it because I really used 'Box in Box' functionality. It was used 
  to keep in one Box composite of different objects (also wrapped in 
Boxes) which were unpacked one by one and interpreted on runtime. It was 
working really good.


>> 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

Probably I knew it. But I just don't remember now from where I did take it.

Hacking Tango components to work with Phobos seems to be very popular 
these days... Recently I also hacked Environment.d from Tango to work 
with Phobos (used in ProgramOptions). :-)


>> ...
>>
>> 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.
> 

isEmpty() is much better.

> As for clearing it...
> 
> v = Variant.init;
> 
> Not sure if you'd gain much by having a clear member.

clear() seems to be a little bit more explanatory.


>> 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.

So should be just improvement request :-)

>> 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! :)
> 

I will create ticket for Tango to improve available implementation and 
fix above bug.

I am thinking about migrating ProgramOptions to Variant, but above 
issues should be ironed out before.

>> ------
>>
>> '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