
Boost : 
From: Simon Buchan (simon_at_[hidden])
Date: 20050923 01:18:40
Dan McLeran wrote:
>>let's finally do it  C++ lacks bounded types and it's high time to fix
>>that! ;)
>
>
> I agree. I had been programming in C++ for a number of years before I was
> introduced to Ada. I loved the strict typing one can do in Ada and I would
> like to have at least some of these facilities in C++ as well (since that is
> what I use every day). I will certainly check out what you've posted
> (bounded types). One thing to keep in mind as we move forward with this is
> that, IMO, we need to support as much compiletime computation as much as
> possible. One thing I am struggling with is how to support both bounded
> floatingpoint types, but as the same time, have a bounded types template be
> able to be used from boost::mpl for compiletime computation.
>
> Regards,
>
> Dan McLeran
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
>
AFAIK, no compiler actually supports compiletime floatingpoint
compilation, since there is no general guarantee that the same
architecture would be running the program (think crosscompiles), and
almost every floatingpoint operation is "implementationdefined",
basicly, could do anything at all.
Say: PPC has 128bit long doubles, x86 only has 80bits, but x86
internally always uses long doubles for calculations, even with 32bit
floats, and therefore gives different results than the PPC. I can't
remember if those statements are accurate, but something like that goes on.
You could try a factory function taking constant T's, hoping the
compiler can constantpropagate through function calls (since it would
be inline, it should be able to), and overload that for integral
expressions? (enable_if<> should be useful here) ie:
template <typename T>
class bounded_t
{ // just a boring runtime checked version
}
template <int min, int max>
class bounded_t<int>// and char, (un)signed char, wchar_t, etc...
{ // fancy compiletime version
}
template <typename T>
bounded_t<T> bounded(const T& t, const T& min, const T& max, int dummy =
disable_if<mpl::is_integral<T>, int>)
{ return bounded<T>(t, min, max);
}
template <typename T>
bounded_t<T, int, int> bounded(const T& t, const T min, const T max, int
dummy = enable_if<mpl::is_integral<T>, int>)
{ return bounded_t<T, min, max>(t);
}
BTW, I have NO idea whether anything like that would ever work, on any
farout plane of the universe. You have been warned.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk