|
Boost Users : |
Subject: Re: [Boost-users] [phoenix] adding const to member_variable bind
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2008-11-11 22:21:48
AMDG
Joel de Guzman wrote:
>> There is no way for result to distinguish between these cases,
>> even though they are different.
>
> Out of curiosity, how does Boost.Bind and Lambda.Bind behave in this
> regard?
It looks like:
a) bind always constifies the return type of a pointer to a data member.
b) lambda does not strip references in its return type deduction.
#include <boost/spirit/home/phoenix/bind.hpp>
#include <boost/spirit/home/phoenix/core.hpp>
#include <boost/bind.hpp>
#include <boost/ref.hpp>
#include <boost/lambda/bind.hpp>
struct x {
int m;
};
void boost_bind() {
using namespace boost;
x x_ = {0};
bind(&x::m, x_)();
bind(&x::m, ref(x_))() = 1; // does not compile--returns const int&
bind(&x::m, cref(x_))();
}
void boost_lambda() {
namespace lambda = boost::lambda;
x x_ = {0};
lambda::bind(&x::m, x_)();
lambda::bind(&x::m, lambda::var(x_))() = 1;
lambda::bind(&x::m, lambda::var(static_cast<const x&>(x_)))();
}
void boost_phoenix() {
namespace phoenix = boost::phoenix;
x x_ = {0};
phoenix::bind(&x::m, phoenix::val(x_))(); // does not compile
phoenix::bind(&x::m, phoenix::ref(x_))() = 1;
phoenix::bind(&x::m, phoenix::cref(x_))(); // does not compile
}
In Christ,
Steven Watanabe
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