Re: Defect: Missing fundamental feature!
francis@robinton.demon.co.uk (Francis Glassborow) writes:
In article <u1wtlta8a.fsf@boost-consulting.com>, David Abrahams
<dave@boost-consulting.com> writes
Testing that the cast can be performed implicitly is really the best
way we have of guessing whether a cast will be safe. As an
alternative to static_cast, implicit_cast helps.
I wonder if we could restrict implicit_cast so that it will never
apply a narrowing conversion or would that destroy its use?
No, because the user can always define such a narrowing conversion of
his own (e.g. rational=>int). We could, however, restrict it so that
no built-in narrowing conversions occur, which should account for most
such conversions... except that you'd still want to allow Derived* =>
Base*, which is narrowing (at least, it's lossy). And if you could
work out all those details, what would you call such a cast and how
would you make it teachable?
Sometimes a simple design that does less is better than a more capable
design with lots of special cases.
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
---
[ 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 ]