|
Boost Users : |
Subject: [Boost-users] [lambda] Can't see the wood for the trees"
From: Robert Jones (robertgbjones_at_[hidden])
Date: 2008-11-21 08:01:00
I have a little code snippet...
#include <iostream>
#include "boost/range.hpp"
#include "boost/function.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" );
}
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...
$ g++ -o junk.exe junk.cpp
junk.cpp: In copy constructor `std::basic_ios<char, std::char_traits<char>
>::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
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.
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