Re: Dumbed-down
kwikius wrote:
> James Kanze wrote:
>> kwikius wrote:
>> > James Kanze wrote:
>> >> Untested, but there's got to be a simpler solution.
>> > http://www.boost.org/libs/numeric/conversion/doc/index.html
>> When I look at the paragraph "Range Checking Logic", in the
>> documentation, I'm not sure that they've found a simpler
>> solution.
> Don't know quite how to put this, but their solution must be
> simpler, since it actually works. Heres a quick test of your
> solution, tried in VC7.1 and gcc4.0
Actually works doesn't necessarily mean simpler. The original
suggestion I was responding to was far, far simpler than
anything in Boost or that I have proposed. It didn't work for
negative values, of course, but it was simple.:-)
For the rest, I don't doubt that the solution in Boost works; it
wouldn't have made it into Boost if it hadn't. It even treats a
number of issues that hadn't even occured to me, like rounding
mode. (It's also well documented, which for publicly available
code outside of Boost is rather exceptional.)
> int main()
> {
> int result1 =
> numeric_cast<int>(static_cast<double>(std::numeric_limits<int>::max())=
);
> std::cout << result1 <<'\n';
> int result2 =
> numeric_cast<int>(static_cast<double>(std::numeric_limits<int>::max())
> + 1);
> std::cout << result2 <<'\n';
> }
> In my definition of simpler, the boost version is *considerably*
> simpler ....... ;-)
I'm not sure what point you're trying to argue. If you mean
using a working solution from Boost is a lot simpler than
writing one of your own which probably doesn't work for a few
corner cases, then I fully agree. Using working code written by
someone else is always simpler than trying to develop something
on your own.
I was talking not about use in a project, but about the
implementation. I would be very surprised that the internal
implementation of Boost was very simple, given all of the issues
that the explicitly address.
--
James Kanze kanze.james@neuf.fr
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France +33 (0)1 30 23 00 34
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]