Help with a boost::lambda problem and boost::array?
Is there a solution?
It appeared to me that the likely winner was: http://www.boost.org/doc/libs/1_37_0/doc/html/lambda/extending.html Then it seems we would use the boost array's typedef value_type to get the return type. However, I do not see operator[] overloading in the list of supporting operators here. But the following code compiles: //Testing lambda and vectors/arrays. using lambda::_1; std::vector<Real> vec(1); vec[1] = 0; boost::function<Real (std::vector<Real>)> vec_f = _1[0]; //Returns the 0'th element. Hence, it seems that this type of action is supported. Any idea where the sourcecode for the std::vector lambda operators are? might be useful to just copy/paste. Also, I wonder if there is any way to do this generically for all vector/array types supporting the Container concept? (I use a lot of ublas::vectors). And if operator() is also supported, I use a lot of ublas::matrix as well, so this would be nice to have in lambda. Jesse
Hello I don't know why this version works std::vector<Real> vec(2); vec[0] = 1; vec[1] = 2; boost::function<Real (std::vector<Real>)> vec_f = _1[0]; //Returns the 0'th element. boost::function<Real (std::vector<Real>)> vec_f1 = _1[0] * _1[1]; but this one doesn't. std::vector<Real> vec(2); vec[0] = 1; vec[1] = 2; boost::function<Real (const std::vector<Real>&)> vec_f = _1[0]; //Returns the 0'th element. boost::function<Real (const std::vector<Real>&)> vec_f1 = _1[0] * _1[1]; B/Rgds Max From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of jesseperla@gmail.com Sent: Friday, January 23, 2009 1:37 AM To: Boost Users Mailing List Subject: [Boost-users] Help with a boost::lambda problem and boost::array?
Is there a solution?
It appeared to me that the likely winner was: http://www.boost.org/doc/libs/1_37_0/doc/html/lambda/extending.html Then it seems we would use the boost array's typedef value_type to get the return type. However, I do not see operator[] overloading in the list of supporting operators here. But the following code compiles: //Testing lambda and vectors/arrays. using lambda::_1; std::vector<Real> vec(1); vec[1] = 0; boost::function<Real (std::vector<Real>)> vec_f = _1[0]; //Returns the 0'th element. Hence, it seems that this type of action is supported. Any idea where the sourcecode for the std::vector lambda operators are? might be useful to just copy/paste. Also, I wonder if there is any way to do this generically for all vector/array types supporting the Container concept? (I use a lot of ublas::vectors). And if operator() is also supported, I use a lot of ublas::matrix as well, so this would be nice to have in lambda. Jesse
AMDG Max wrote:
I don't know why this version works
std::vector<Real> vec(2); vec[0] = 1; vec[1] = 2; boost::function<Real (std::vector<Real>)> vec_f = _1[0]; //Returns the 0'th element. boost::function<Real (std::vector<Real>)> vec_f1 = _1[0] * _1[1];
but this one doesn't.
std::vector<Real> vec(2); vec[0] = 1; vec[1] = 2; boost::function<Real (const std::vector<Real>&)> vec_f = _1[0]; //Returns the 0'th element. boost::function<Real (const std::vector<Real>&)> vec_f1 = _1[0] * _1[1];
The handling of const is wrong in boost/lambda/detail/operator_return_type_traits.hpp The containers start on line 894. In Christ, Steven Watanabe
Considering also that neither typedef boost::array<double, 2> array_t; boost::function<double (const array_t&)> f = _1[0]; nor typedef boost::array<double, 2> array_t; boost::function<double (array_t)> f = _1[0]; works, I think there seems to be a patch for lambda to make it more boost::array friendly and more const-aware. Is it theoriotically possible? Thanks for attention. B/Rgds Max
I don't know why this version works
std::vector<Real> vec(2); vec[0] = 1; vec[1] = 2; boost::function<Real (std::vector<Real>)> vec_f = _1[0]; //Returns
the
0'th element. boost::function<Real (std::vector<Real>)> vec_f1 = _1[0] * _1[1];
but this one doesn't.
std::vector<Real> vec(2); vec[0] = 1; vec[1] = 2; boost::function<Real (const std::vector<Real>&)> vec_f = _1[0]; //Returns the 0'th element. boost::function<Real (const std::vector<Real>&)> vec_f1 = _1[0] * _1[1];
B/Rgds Max
AMDG jesseperla@gmail.com wrote:
Is there a solution?
It appeared to me that the likely winner was: http://www.boost.org/doc/libs/1_37_0/doc/html/lambda/extending.html
Then it seems we would use the boost array's typedef value_type to get the return type. However, I do not see operator[] overloading in the list of supporting operators here.
That's a documentation problem. It's other_action<subscript_action>.
But the following code compiles: //Testing lambda and vectors/arrays. using lambda::_1; std::vector<Real> vec(1); vec[1] = 0; boost::function<Real (std::vector<Real>)> vec_f = _1[0]; //Returns the 0'th element.
Hence, it seems that this type of action is supported. Any idea where the sourcecode for the std::vector lambda operators are? might be useful to just copy/paste.
It's all in boost/lambda/detail/operator_return_type_traits.hpp
Also, I wonder if there is any way to do this generically for all vector/array types supporting the Container concept? (I use a lot of ublas::vectors). And if operator() is also supported, I use a lot of ublas::matrix as well, so this would be nice to have in lambda.
In Christ, Steven Watanabe
participants (3)
-
jesseperla@gmail.com
-
Max
-
Steven Watanabe