|
Boost Users : |
From: Stuart Dootson (stuart.dootson_at_[hidden])
Date: 2006-10-23 13:03:20
On 10/23/06, Sebastian Weber <sebastian.weber_at_[hidden]> wrote:
> Hello there!
>
> I'm about to explore the power of boost::bind, but I am still a
> beginner. Maybe the question is rather stupid, but the following code
> does not compile and I do not understand why:
>
> typedef std::vector<std::size_t> data_t;
>
> data_t dataVec;
>
> ... populate dataVec ...
>
> std::size_t shiftIndex = 3;
>
> boost::function<std::size_t& (std::size_t)> shiftedData =
> boost::bind(&data_t::at, &dataVec, _1 - shiftIndex);
>
> The error message is something like
>
> /home/sweber/graphpkg/libs/boost/boost/function/function_template.hpp:119: error: invalid
> initialization of reference of type 'size_t&' from expression of type
> 'const
> unsigned int'
>
> My system is a debian sarge with a g++-3.3 and boost 1.33.1.
>
> What I'm trying to do is to shift the index of the data-vector such that
> index 3 would address the first element.
>
> Thanks for any help.
>
>
> Greetings,
>
> Sebastian Weber
Boos.Bind will only do the binding bit - what you're wanting to do
(apply an expression to the parameter at call-time) can be
accomplished with Boost.Lambda - which has its own bind facility (with
pretty much exactly the same syntax as Boost.Bind) that you'll need to
use instead of Boost.Bind.
HTH
Stuart Dootson
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