|
Boost : |
From: Valentin Bonnard (Bonnard.V_at_[hidden])
Date: 2000-01-29 15:10:46
John Maddock wrote:
> >I agree that it would be nice to allow overloading of functions in
> namespace
> >std. However, in submitting a DR, it would be prudent to look at this and
> >other, if any, pitfalls, and propose restrictions on overloading and/or
> std
> >library design to avoid future problems.
>
> There are other problems with overloading standard library functions
These aren't new. We already have them today, in the standard.
> #include <algorithm>
> #include <locale>
>
> template <typename T> struct myUDT{};
>
> namespace std
> {
> template <typename T, typename U>
> void fill(myUDT<T>*, myUDT<T>*, const U&){}
^
add <myUDT<T>*, U> here
> }
>
> template <typename T>
> void g(T t)
> {
> }
>
> void foo()
> {
> std::fill<char*, char >(0, 0, 0); // ambiguous
You don't mean char*, do you ?
How is it different w/ specialisation ?
> }
>
> In each case there are workarounds, however the point here is that the
> presence of an overload in namespace std may prevent overwise perfectly
> legal C++ code from compiling - and that code could be in your standard
> library - in other words simply including a user-defined header that
> defines overloads in std can disable standard library code.
That's correct. It would basically imply that lib code
cannot use standard lib templates or function, only
non-standard ones. And that's _not_ what we wanted. YADR.
> I'm not sure
> that the kind of usage given is all that likely (in fact I'm sure that its
> not), but even so, the standard seems to be correct when it says that
> overloads in std produce undefined behaviour.
???
It *seems* to be correct ? How could the Standard be wrong,
since it is the Truth ?
-- Valentin Bonnard
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk