Boost logo

Boost Users :

From: Matt Hortman (matt_at_[hidden])
Date: 2005-04-13 07:23:38


Hello,

I feel almost silly asking this but:

I can only get the code listed below to compile if I remove the
comments on the namespace statements, placing my custom operator<< in
the boost::detail::variant namespace. Otherwise I get the error

c:\Boost\include\boost-1_32\boost\variant\detail\variant_io.hpp(64) :
error C2679: binary '<<' : no operator found which takes a right-hand
operand of type 'const T1' (or there is no acceptable conversion)

from VC++ 7.1 and a similar error from both gcc 3.3 and 3.4. I'm
using boost 1.32 on both WinXP and FreeBSD. Looking at the code in
variant_io.hpp, I see no reason why it should not work without the
namespace statements. Is there something fundamental about namespaces
that I don't understand?

Thanks,

-Matt

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

typedef std::vector<std::string> strlist;
typedef boost::variant<int, strlist> ConfigItem;

//namespace boost { namespace detail { namespace variant {

inline std::ostream& operator<< (std::ostream& os, const strlist& slist) {
        strlist::const_iterator it;
        for (it=slist.begin(); it!=slist.end(); ++it)
                os << *it << ", ";
        return os;
        }

//}}}

//using namespace boost::detail::variant;

void main (void) {

        strlist sl;
        std::cout << sl << std::endl; //compiles fine

        ConfigItem v;
        std::cout << v << std::endl; // error no operator found
        }


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net