
Comments are inline... On Fri, Nov 21, 2008 at 1:01 PM, Robert Jones <robertgbjones@gmail.com>wrote:
I have a little code snippet...
#include <iostream> #include "boost/range.hpp" #include "boost/function.hpp" #include "boost/lambda/lambda.hpp"
#include <boost/lambda/lambda.hpp>
int main( ) { using namespace boost::lambda;
typedef int block[2][4];
boost::function< int(boost::range_value< block >::type) > third = _1[2];
block values = {{0,1,2,3},{4,5,6,7}};
std::for_each(boost::begin(values), boost::end(values), std::cout << third << "\n" );
If you replace the above line with ... std::for_each(boost::begin(values), boost::end(values), std::cout << boost::lambda::bind(third, _1) << "\n"); ... it all appears to work.
}
Although, it clearly isn't optimal in terms of performance. Perhaps accessing the third element could be better achieved with a functor templatised on the index value?
which I want to print the third element of each row of values. I can see that what I've written is not quite right, since the compiler quite reasonably complains that it doesn't kknow how to print a function object, but I can't seem to write the correct incantation! The error message, if it helps is...
::basic_ios(const std::basic_ios<char, std:: char_traits<char> >&)': /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/ios_base.h:781: error: `std::ios_base::ios_base(const std::ios_base&) ' is private junk.cpp:17: error: within this context junk.cpp: In function `int main()': junk.cpp:17: error: initializing argument 3 of `_Function std::for_each(_InputIterator, _InputIterator, _Function) [wi
$ g++ -o junk.exe junk.cpp junk.cpp: In copy constructor `std::basic_ios<char, std::char_traits<char> th _InputIterator = int (*)[4], _Function = std::basic_ostream<char, std::char_traits<char> >]' /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_algo.h: In function `_Function std::for_each(_InputIterator, _Inp utIterator, _Function) [with _InputIterator = int (*)[4], _Function = std::basic_ostream<char, std::char_traits<char> >] ': junk.cpp:17: instantiated from here /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_algo.h:158: error: no match for call to `(std::basic_ostream<char , std::char_traits<char> >) (int[4])'
Thank Folks!
- Rob.
I hope this all helps. Regards, Neil Groves
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost