[mpl] arithmetic feature request

It would be nice if we could represent all compile-time algebraic operations in Boost.Units using MPL arithmetic. At present, MPL supports negate, adds, subtracts, times, divides. Boost.Units additionally would require : 1) unary_plus - the compile-time equivalent of operator+(T) 2) unary_minus - the compile-time equivalent of operator-(T); this is identical to current mpl::negate, but it would be nice to have it for notational consistency with unary_plus 3) power<T,U> (or pow<T,U>) - the compile-time equivalent of pow(T,U) 4) root<T,U> - the compile-time equivalent of pow(T,1/U); can be implemented with power<T,U>, but this is a nicer syntax to eliminate its remaining compile-time algebra operators. Any thoughts on whether this would be a worthwhile addition to MPL? Matthias

Hi, to bring this up I believe this is kinda useful. I had to write my own power<> and root<> recently and wondered the excact same thing. Have you written these templates? Maybe you could submit a patch, my version does not use the MPL, I just rely on the good compile time evaluation of constant expressions by gcc. Kevin On 4/21/07, Matthias Schabel <boost@schabel-family.org> wrote:
It would be nice if we could represent all compile-time algebraic operations in Boost.Units using MPL arithmetic. At present, MPL supports negate, adds, subtracts, times, divides. Boost.Units additionally would require :
1) unary_plus - the compile-time equivalent of operator+(T) 2) unary_minus - the compile-time equivalent of operator-(T); this is identical to current mpl::negate, but it would be nice to have it for notational consistency with unary_plus 3) power<T,U> (or pow<T,U>) - the compile-time equivalent of pow(T,U) 4) root<T,U> - the compile-time equivalent of pow(T,1/U); can be implemented with power<T,U>, but this is a nicer syntax
to eliminate its remaining compile-time algebra operators. Any thoughts on whether this would be a worthwhile addition to MPL?
Matthias

I briefly thought about trying to put together a patch, but, after looking at the code for mpl/multiplies.hpp, I quickly decided that it was way more of a can of worms than I feel comfortable opening. I imagine that it would be relatively simple to do for someone with familiarity with the internals of MPL, but that isn't me... root<> also raises some issues since it only makes sense (on integers) for roots of integers that are themselves integral. This is obviously not a problem for rational roots... Matthias
Hi, to bring this up I believe this is kinda useful. I had to write my own power<> and root<> recently and wondered the excact same thing. Have you written these templates? Maybe you could submit a patch, my version does not use the MPL, I just rely on the good compile time evaluation of constant expressions by gcc.
Kevin
On 4/21/07, Matthias Schabel <boost@schabel-family.org> wrote:
It would be nice if we could represent all compile-time algebraic operations in Boost.Units using MPL arithmetic. At present, MPL supports negate, adds, subtracts, times, divides. Boost.Units additionally would require :
1) unary_plus - the compile-time equivalent of operator+(T) 2) unary_minus - the compile-time equivalent of operator-(T); this is identical to current mpl::negate, but it would be nice to have it for notational consistency with unary_plus 3) power<T,U> (or pow<T,U>) - the compile-time equivalent of pow(T,U) 4) root<T,U> - the compile-time equivalent of pow(T,1/U); can be implemented with power<T,U>, but this is a nicer syntax
to eliminate its remaining compile-time algebra operators. Any thoughts on whether this would be a worthwhile addition to MPL?
Matthias
Unsubscribe & other changes: http://lists.boost.org/mailman/ listinfo.cgi/boost

--- Matthias Schabel wrote:
I imagine that it would be relatively simple to do for someone with familiarity with the internals of MPL, but that isn't me...
My MPL.Math sublibrary, available in the Vault under the Template Metaprogramming directory, contains implementations of the power<> and integral_power<> metafunctions that you seek.
root<> also raises some issues since it only makes sense (on integers) for roots of integers that are themselves integral. This is obviously not a problem for rational roots...
I might consider a generalized root<> metafunction if I can get significant compile-time savings over the naive implementation. MPL.Math already has a square_root<> metafunction. Cromwell D. Enage __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com

My MPL.Math sublibrary, available in the Vault under the Template Metaprogramming directory, contains implementations of the power<> and integral_power<> metafunctions that you seek.
Do you have any plans to submit this for review? We already have the functionality in the upcoming Boost.Units library, but it would be nice for symmetry to have all the metamath be supported through MPL rather than having to mix mpl::negate/adds/subtracts/multiplies/ divides with our own metafunctions for unary_plus/pow/root... I certainly think it would be nice to have support for these in Boost itself. Unfortunately, since this would be used within the library itself, we're constrained to use only other Boost libraries... Matthias

Sorry for the long delay in replying. --- Matthias Schabel wrote:
My MPL.Math sublibrary, available in the Vault under the Template Metaprogramming directory, contains implementations of the power<> and integral_power<> metafunctions that you seek.
Do you have any plans to submit this for review?
Yes. As I've stated before, documentation is the biggest hurdle. I have not yet been successful in using Docutils to autogenerate HTML/PDF the way Aleksey does, so I'm studying BoostBook/QuickBook as an alternative. The only other option is to hand-crank a hundred or so HTML pages, which I don't relish doing. Cromwell D. Enage __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
participants (4)
-
Cromwell Enage
-
Kevin Sopp
-
Matthias Schabel
-
Steven Watanabe