Boost logo

Boost :

From: John Maddock (John_Maddock_at_[hidden])
Date: 2000-01-29 08:05:52

>I agree that it would be nice to allow overloading of functions in
>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
>library design to avoid future problems.

There are other problems with overloading standard library functions
relating to the use of explicit template parameters, consider the following
(somewhat contrived I admit) program that illustrates the problem:

#include <algorithm>
#include <locale>

template <typename T> struct myUDT{};

namespace std
template <typename T, typename U>
void fill(myUDT<T>*, myUDT<T>*, const U&){}

template <typename T>
const myUDT<T>& use_facet(const locale&)
   static myUDT<T> t;
   return t;


template <typename T>
void g(T t)

void foo()
   char c[5];
   std::use_facet<int>(std::locale()); // ambiguous
   std::fill<char*, char >(0, 0, 0); // ambiguous
   g(std::fill<char*,char>); // ambiguous

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. 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.

- John.

Boost list run by bdawes at, gregod at, cpdaniel at, john at