Boost logo

Boost Users :

From: klaus triendl (triendl.kj_at_[hidden])
Date: 2006-06-29 19:45:28


Hi,

I'm rather new to lambdas.
I wanted to use them to stream objects into a special stream (not a stl
stream).

the following code outlines the situation:

----
#include <iostream>
#include <list>
#include <algorithm>
#include <boost/ref.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/lambda/lambda.hpp>
using namespace std;
using namespace boost;
using boost::lambda::_1;
class MyStream
{
public:
   MyStream() {}
};
class MySubStream: public MyStream
{
public:
   MySubStream(MyStream*) {}
};
MyStream& operator <<(MyStream& os, const int&)
{
   return os;
}
int main()
{
   list<shared_ptr<int> > cont;
   MyStream osTop;
   MySubStream osSub(&osTop);
   for_each(cont.begin(), cont.end(), ref(osSub) << *_1);
   return 0;
}
----
g++ outputs error:
'/usr/include/boost/lambda/detail/operator_lambda_func_base.hpp:212: 
error: conversion from 'MyStream' to non-scalar type 'MySubStream' 
requested'.
MS VC 2003.net says:
boost\lambda\detail\operator_lambda_func_base.hpp(212) : error C2664: 
'MySubStream::MySubStream(MyStream *)' : cannot convert parameter 1 from 
'MyStream' to 'MyStream *'.
The question is whether my code is correct at all and how I could use 
lambdas the right way.
Thanks!
Klaus Triendl

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