Boost logo

Boost :

Subject: Re: [boost] [explore] Library Proposal: Container Streaming
From: Jeffrey Faust (jeff_at_[hidden])
Date: 2009-11-30 22:04:19


Zachary Turner wrote:
> John Bytheway wrote:
> > You could put them in the global namespace? I think that would
> > conform better to the letter of the rules, without really being any
> > safer in practice.
> I'd rather put them in a library specific namespace in that case, and
> require the programmer to put a using declaration in the translation
> unit.

Below is an example of why that won't work for all cases. The only way
for variant::operator<< to access operator<<(vector) is to rely on ADL
and put the operator<< in the std namespace.

#include <boost/variant.hpp>
#include <iostream>
#include <vector>

namespace explore
{
   template<typename T>
   std::ostream& operator<<(std::ostream& ostr, const std::vector<T>& v)
   {
      // ...
      return ostr;
   }
}

int main()
{
   using namespace explore;
   boost::variant<std::vector<int> > v;
   std::cout << v << std::endl;
}

-- Jeff Faust


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk