Boost logo

Boost :

Subject: Re: [boost] [lambda] Serialising Lmanda functions
From: Giovanni Piero Deretta (gpderetta_at_[hidden])
Date: 2008-10-07 12:05:06


On Tue, Oct 7, 2008 at 5:57 PM, Robert Jones <robertgbjones_at_[hidden]> wrote:
> Is there a 'standard' solution to this problem?
>
> #include <list>
> #include <iostream>
> #include "boost/lambda/lambda.hpp"
>
> typedef std::list<unsigned> List;
> std::ostream & operator<<( std::ostream & s, const List & );
>
> int main( )
> {
> using namespace boost::lambda;
> List my_list;
>
> ( std::cout << _1 << "\n" )( my_list );
> }
>
> The compiler cannot find a match for operator<<() because the operator
> and the type are defined in different namespaces, but it's really a
> nuisance!
>

Dirty trick that might work:
just write your own allocator that simply inherit from the standard
allocator (you might need to add forwarding constructors). Put it in
the same namespace you declare your operator<<, then

   typedef std::list<unsigned, my_alloc> List;

ADL should take care of everything.

-- 
gpd

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