Boost logo

Boost Users :

From: Mojmir Svoboda (mojmir.svoboda_at_[hidden])
Date: 2007-06-20 11:37:03


Hello,

i want to use bind to create a pair and forward it to an std::ostream, i.e. like:

    std::for_each(vec.begin(), vec.end(),
                bind(&write,
                    std::cout,
                    bind(constructor<std::pair<value_t, value_t> >(), _1, _1)));

but the compiler says:
    ios_base.h:781: error: 'ios_base(const ios_base &)' is private
    boost/boost/lambda/detail/bind_functions.hpp:472: error: within this context
    boost/boost/lambda/detail/function_adaptors.hpp: In static member function
       `static void boost::lambda::function_adaptor<
            void (*)(ostream &, const pair<value_t, value_t> &)
>::apply(
                void (*)(ostream &, const pair<value_t, value_t> &),
                const ostream &,
                const pair<value_t, value_t> &)'
        ...
it seem that temporary is created? why? how to avoid it?

i've tried the obvious way (at least for me):

    std::for_each(vec.begin(), vec.end(),
            (std::cout << bind(constructor<std::pair<value_t, value_t> >(), _1, _1)));

but now the output from compiler is kind of 'heavy stuff' and i'm having difficulties
to figure out what am i doing wrong.
can you help me, please?

many thanks for your attention,
Mojmir

--------8<---- complete source ------

#include <boost/lambda/bind.hpp>
#include <boost/lambda/construct.hpp>
#include <memory>
#include <vector>
#include <iostream>
using namespace boost::lambda;

typedef int value_t;
typedef std::vector<value_t> vect_t;
typedef std::vector<std::pair<value_t, value_t> > vect2_t;

std::ostream & operator<< (std::ostream & os, std::pair<value_t, value_t> const & p)
{ return os; }

void write (std::ostream & os, std::pair<value_t, value_t> const & p) { }

int main ()
{
    vect_t vec;
    vect2_t vec2;

    vec.push_back(1);
    
    std::transform(vec.begin(), vec.end(), std::back_inserter(vec2),
                bind(constructor<std::pair<value_t, value_t> >(), _1, _1)); // ok

/*
    std::for_each(vec.begin(), vec.end(),
                bind(&write,
                    std::cout,
                    bind(constructor<std::pair<value_t, value_t> >(), _1, _1))
                );

    std::for_each(vec.begin(), vec.end(),
                (std::cout << bind(constructor<std::pair<value_t, value_t> >(), _1, _1)));
*/
}

This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you.


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