|
Boost Users : |
From: Bruce Trask (Bruce.Trask_at_[hidden])
Date: 2005-03-21 08:52:07
Hello,
I need to create a sequence of float values that the user can put in at
compile time. Since floats cannot be used as template params I am
assuming I cannot use vector_c in any way.
My plan was to have the user input the initial float values as
mpl::vector<char> and then convert the chars to string and then the
string to float when I needed to use it at runtime. My other idea was
to make a struct that inherited from mpl::pair and have the first part
be the integral part and the second part be the decimal part and again,
construct the float from that.
So the two ideas look something like:
// idea 1 - a bit odd but need to get around C++ on this one
typedef mpl::vector_c<char,'8','9','.','4','5'> eightyninepointfourfive;
typedef mpl::vector_c<char,'2','4','.','1','1'> twentyfourpointoneone;
typedef mpl::vector<eightyninepointfourfive, twentyfourpointoneone>
floatseq;
// idea 2
template<int INTEGRAL, int DECIMAL>
struct float_ : mpl::pair<mpl::integral_c<int, INTEGRAL>,
mpl::integral_c<int, DECIMAL> >
{
};
typedef mpl::vector<float_<89, 45>, float_<24,11> > floataspairseq;
typedef float_<89,45>::first the89part;
typedef float_<89,45>::second the45part;
// end ideas
What do you think of these ideas?
I am assuming that there must be other solutions and perhaps these are
not the best. Wanted to bounce these of the list for comments.
Thanks in advance.
Regards,
Bruce
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net