compose, bind and a doubled ref problem
Hi!
The code below compiles fine if You return to Value
semantics and replace "const Vector&" with "Vector".
But with reference to vector two compilers (Intel-7.0
and gcc-3.2.1) "throw" with a "reference to reference" error.
How can I achieve what I want here?
Do I have to apply cref somewhere?
I do not want to change the type of "l" in this example.
Also the signature of Vector::operator() and GetValue
is fixed. Anything else may undergo a change.
#include <iostream>
#include <cstddef>
#include "boost/function.hpp"
#include "boost/bind.hpp"
#include "boost/compose.hpp"
struct Vector
{
double operator()(size_t j) const
{
std::cerr << "get value at index " << j << std::endl;
return 99.0;
}
};
double GetValue(const Vector& V, size_t j)
{
return V(j);
}
double Add(double d1, double d2)
{
return d1 + d2;
}
int main()
{
using namespace boost;
Vector V;
function
From: "Markus Werle"
The code below compiles fine if You return to Value semantics and replace "const Vector&" with "Vector". But with reference to vector two compilers (Intel-7.0 and gcc-3.2.1) "throw" with a "reference to reference" error.
How can I achieve what I want here?
[...]
#include "boost/bind.hpp" #include "boost/compose.hpp"
It's simple, don't use compose. :-) [...]
function
l = compose_f_gx_hx(Adder, h1, h2);
Change to bind(Adder, bind(h1, _1), bind(h2, _1));
participants (2)
-
Markus Werle
-
Peter Dimov