Constructor with parameters -- Lambda

Thanks for the input on trying to use boost::lambda::bind instead of boost::bind, unfortunately there is no bind in the lambda namespace. I'm using Boost 1.35, and in my version "namespace lambda" only exists in boost\lambda\construct.hpp and only contains a single templated struct constructor, there is no bind available :( Any ideas? I'm trying all sort of funny syntax variations to no avail... Message: 4 Date: Fri, 13 Jun 2008 15:37:58 -0700 From: "albert meyburgh" <ameyburgh@gmail.com> Subject: [boost] Constructor with parameters -- Lambda To: boost@lists.boost.org Message-ID: <35f053b10806131537o4b85769fg84a88bc0c70dddc4@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Hi, I'm trying to use the lambda constructor provided in boost and it's not compiling. class someclass { someclass(sometype, int x) } std::vector v<sometype> std::vector v2<someclass> std::transform( v.begin(), v.end(), std::back_inserter( v2 ), boost::bind( boost::lambda::constructor<someclass>(), _1, 5) ); // where 5 is a constant int parameter for x to the constructor Resulting in Error 1 error C2039: 'result_type' : is not a member of 'boost::lambda::constructor<T>' boost_1_35_0\boost\bind.hpp 67 Error 2 error C2146: syntax error : missing ';' before identifier 'type' boost_1_35_0\boost\bind.hpp 67 Error 3 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int boost_1_35_0\boost\bind.hpp 67 Error 4 error C2208: 'boost::_bi::type' : no members defined using this type boost_1_35_0\boost\bind.hpp 67 Error 5 fatal error C1903: unable to recover from previous error(s); stopping compilation boost_1_35_0\boost\bind.hpp 67 What is wrong with my syntax? ------------------------------ Message: 5 Date: Fri, 13 Jun 2008 15:57:59 -0700 From: Steven Watanabe <watanabesj@gmail.com> Subject: Re: [boost] Constructor with parameters -- Lambda To: boost@lists.boost.org Message-ID: <4852FB77.4000902@providere-consulting.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed AMDG albert meyburgh wrote:
boost::bind( boost::lambda::constructor<someclass>(), _1, 5) ); // where 5 is a constant int parameter for x to the constructor
Use boost::lambda::bind. In Christ, Steven Watanabe ------------------------------ Message: 6 Date: Fri, 13 Jun 2008 15:59:14 -0700 From: Eric Niebler <eric@boost-consulting.com> Subject: Re: [boost] Constructor with parameters -- Lambda To: boost@lists.boost.org Message-ID: <4852FBC2.8040606@boost-consulting.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed albert meyburgh wrote:
Hi,
I'm trying to use the lambda constructor provided in boost and it's not compiling.
class someclass { someclass(sometype, int x) }
std::vector v<sometype> std::vector v2<someclass> std::transform( v.begin(), v.end(), std::back_inserter( v2 ), boost::bind( boost::lambda::constructor<someclass>(),
Try boost::lambda::bind() instead of boost::bind(). -- Eric Niebler BoostPro Computing http://www.boostpro.com

AMDG albert meyburgh wrote:
Thanks for the input on trying to use boost::lambda::bind instead of boost::bind, unfortunately there is no bind in the lambda namespace.
I'm using Boost 1.35, and in my version "namespace lambda" only exists in boost\lambda\construct.hpp and only contains a single templated struct constructor, there is no bind available :(
#include <boost/lambda/bind.hpp> In Christ, Steven Watanabe

boost-bounces@lists.boost.org, le 16 juin 2008 12:55:
Thanks for the input on trying to use boost::lambda::bind instead of boost::bind, unfortunately there is no bind in the lambda namespace.
I'm using Boost 1.35, and in my version "namespace lambda" only exists in boost\lambda\construct.hpp and only contains a single templated struct constructor, there is no bind available :(
Any ideas?
Not sure about 1.35 but in the version I use, lambda::bind is defined in boost/lambda/bind.hpp HTH, ------------------ Éric Malenfant

I believe this is a bug in the boost lambda constructor I have worked around the problem with this wrapper: template< typename T > struct LambdaConstructorWrapper : public boost::lambda::constructor< T > { typedef T result_type; }; and using it as such: LambdaConstructorWrapper<MyType> myTypeConstructionWrapper; std::transform( mycontainer.begin(), mycontainer.end(), std::back_inserter( redcontainer ), boost::bind(myTypeConstructionWrapper, _1, WHATEVER_PARM)); It seems to behave as expected by adding this one typedef so it's probably a bug? unless by design it's not supposed to be used this way for some reason that I don't see? On Mon, Jun 16, 2008 at 9:55 AM, albert meyburgh <ameyburgh@gmail.com> wrote:
Thanks for the input on trying to use boost::lambda::bind instead of boost::bind, unfortunately there is no bind in the lambda namespace.
I'm using Boost 1.35, and in my version "namespace lambda" only exists in boost\lambda\construct.hpp and only contains a single templated struct constructor, there is no bind available :(
Any ideas?
I'm trying all sort of funny syntax variations to no avail...
Message: 4 Date: Fri, 13 Jun 2008 15:37:58 -0700 From: "albert meyburgh" <ameyburgh@gmail.com> Subject: [boost] Constructor with parameters -- Lambda To: boost@lists.boost.org Message-ID: <35f053b10806131537o4b85769fg84a88bc0c70dddc4@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1
Hi,
I'm trying to use the lambda constructor provided in boost and it's not compiling.
class someclass { someclass(sometype, int x) }
std::vector v<sometype> std::vector v2<someclass> std::transform( v.begin(), v.end(), std::back_inserter( v2 ), boost::bind( boost::lambda::constructor<someclass>(), _1, 5) ); // where 5 is a constant int parameter for x to the constructor
Resulting in
Error 1 error C2039: 'result_type' : is not a member of 'boost::lambda::constructor<T>' boost_1_35_0\boost\bind.hpp 67 Error 2 error C2146: syntax error : missing ';' before identifier 'type' boost_1_35_0\boost\bind.hpp 67 Error 3 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int boost_1_35_0\boost\bind.hpp 67 Error 4 error C2208: 'boost::_bi::type' : no members defined using this type boost_1_35_0\boost\bind.hpp 67 Error 5 fatal error C1903: unable to recover from previous error(s); stopping compilation boost_1_35_0\boost\bind.hpp 67
What is wrong with my syntax?
------------------------------
Message: 5 Date: Fri, 13 Jun 2008 15:57:59 -0700 From: Steven Watanabe <watanabesj@gmail.com> Subject: Re: [boost] Constructor with parameters -- Lambda To: boost@lists.boost.org Message-ID: <4852FB77.4000902@providere-consulting.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
AMDG
albert meyburgh wrote:
boost::bind( boost::lambda::constructor<someclass>(), _1, 5) ); // where 5 is a constant int parameter for x to the constructor
Use boost::lambda::bind.
In Christ, Steven Watanabe
------------------------------
Message: 6 Date: Fri, 13 Jun 2008 15:59:14 -0700 From: Eric Niebler <eric@boost-consulting.com> Subject: Re: [boost] Constructor with parameters -- Lambda To: boost@lists.boost.org Message-ID: <4852FBC2.8040606@boost-consulting.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
albert meyburgh wrote:
Hi,
I'm trying to use the lambda constructor provided in boost and it's not compiling.
class someclass { someclass(sometype, int x) }
std::vector v<sometype> std::vector v2<someclass> std::transform( v.begin(), v.end(), std::back_inserter( v2 ), boost::bind( boost::lambda::constructor<someclass>(),
Try boost::lambda::bind() instead of boost::bind().
-- Eric Niebler BoostPro Computing http://www.boostpro.com

On Tue, Jun 17, 2008 at 9:31 PM, albert meyburgh <ameyburgh@gmail.com> wrote:
I believe this is a bug in the boost lambda constructor
I have worked around the problem with this wrapper:
template< typename T > struct LambdaConstructorWrapper : public boost::lambda::constructor< T > { typedef T result_type; };
and using it as such:
LambdaConstructorWrapper<MyType> myTypeConstructionWrapper;
std::transform( mycontainer.begin(), mycontainer.end(), std::back_inserter( redcontainer ), boost::bind(myTypeConstructionWrapper, _1, WHATEVER_PARM));
It seems to behave as expected by adding this one typedef so it's probably a bug? unless by design it's not supposed to be used this way for some reason that I don't see?
This is not a bug. As other have said, use boost::*lambda*::bind, not plain bind. Bind expect its first parameter to be a function pointer or a function object which exposes a result_type typedef for result type deduction. Boost.Lambda cannot have a result_type typedef because (in general) the result type depends on the argument type. Boost.Lambda uses the 'sig' protocol for that, which boost.bind doesn't support. boost::lambda::bind does. Of course in a perfect world both boost.bind and boost.lambda would be result_of compatible and these problems won't exist :) HTH, -- gpd
participants (4)
-
albert meyburgh
-
Eric MALENFANT
-
Giovanni Piero Deretta
-
Steven Watanabe