std.boxer vs Any
Bill Baxter
dnewsgroup at billbaxter.com
Tue Oct 9 19:47:07 PDT 2007
Marcin Kuszczak wrote:
> import doost.util.config.ProgramOptions;
> import doost.util.config.CommandLineStorage;
>
> void main(char[][] args) {
> //Definition of simplest options stack
> auto po = (new ProgramOptions)
> .next(
> (new CommandLineStorage(args))
> .caption("Command line options")
> .options()
> ("help,h", "produce help message")
> ("compression", define!(int), "set compression level")
> ("sync", "stores cmdline options in persistent backend")
> ()
> );
>
> //Conecting to storages
> po.connect();
>
> //Reading options
> if ("help" in po) writefln(po);
> if ("compression" in po)
> writefln("Compresson level set to: ", po["compression"].as!(uint));
>
> //Disconnecting storages
> po.disconnect;
> }
>
> ---------->8----------
What's the difference between std.boxer and doost.core.Any?
Seems like they do basically the same thing. Only big difference seems
to be that boxer is a struct, while Any is a class.
Boxer looks to be smarter about conversions (unbox!(uint) in the above
example looks like it would probably work.)
But boxer uses void[] storage, meaning it's not a good idea to use boxer
for floating point values or random hash-like integer values (will lead
to gc leaks).
Anyway, I suppose you had your reasons for writing Any rather than just
going with what's in the library... what were they?
And part B) of my question is -- maybe you could borrow some of the
unboxing logic from boxer to make Any.as!(type) more flexible. To me,
'as' sounds like it's going to be a flexible conversion. Maybe the
current behavior could be renamed to Any.get!(type) or Any.value!(type).
--bb
More information about the Digitalmars-d
mailing list