Preliminary submission - std.rational and std.typelist

Dmitry Olshansky dmitry.olsh at gmail.com
Sat Oct 6 11:32:16 PDT 2012


On 06-Oct-12 21:03, Arlen wrote:
> Greetings,
>
> In one of my D projects a units library was needed, so I decided to port Boost.Units to D.  I've been working on it for the past month or so (mostly on the weekends), and It's about 90% done.  The work has also produced additional functionality not yet available in Phobos, so I've decided to separate them into their own modules and present them here as my preliminary submission.  At the time I wasn't aware of the Boost submission process, otherwise I would have done "Determine Interest" first.  Hopefully nobody has ported Boost.Units to D.
>
> So far the completion of the units library is contingent on the finalization of the design and implementation of the following two modules:
>
> std.rational, which is a small module for rational numbers.
> Source:  https://github.com/Arlen/phobos/blob/units/std/rational.d
> Docs:  http://arlen.github.com/phobos/std_rational.html

Cool, does it work with BigInt?

Also I think there is better version of toString that has signature:
void toString(scope void delegate(const(char)[]) sink)

this toString just use functions like formattedWrite to write chars to 
sink. It thus totally avoids overhead of allocating strings.

Your current code may have some bad impact on performance:
return "(" ~ to!string(res.numerator) ~ "/" ~ to!string(res.denominator) 
~ ")";

Allocates 4 times. ~ operator is convenient shortcut to get job done but 
it's unsuitable for building strings and formatted output.

> std.typelist, which provides the TypeList type and several metafunctions.  The metafunctions are pretty much stolen from Haskell.
> Source:  https://github.com/Arlen/phobos/blob/units/std/typelist2.d
> Docs:  http://arlen.github.com/phobos/std_typelist2.html
>

I concur with the general idea that it needs to be folded into 
std.typetuple unless there is some *really* compelling reason not to.

> I wasn't aware that we already had std.typelist module in Phobos until I was ready to submit my work.  I suppose the work was abandoned or it was never finalized?  There are differences in typelist2.d and typelist.d, though.

Old and never finalized.
Recently re-'discovered'. It never participated in
the compilation of Phobos and sort of went under the radar.


-- 
Dmitry Olshansky


More information about the Digitalmars-d mailing list