|
Boost : |
From: Robin.Hu (huxw_at_[hidden])
Date: 2002-12-09 14:11:35
I use the header file <boost/bind.hpp> instead of <boost/lambda/bind.hpp>
by mistake. Thanks for your help.
On Mon, 9 Dec 2002 13:16:38 -0500 (EST)
Jaakko Jarvi <jajarvi_at_[hidden]> wrote:
> The algorithm.hpp header is badly broken in 1.29 (wrong file
> in the wrong place at the wrong time). This is fixed in the cvs main
> trunk.
>
> The following program compiles and runs fine (with gcc3.2).
>
> Cheers, Jaakko
>
>
> // ------------------
> #include <boost/lambda/lambda.hpp>
> #include <boost/lambda/bind.hpp>
> #include <boost/lambda/algorithm.hpp>
>
> #include <vector>
> #include <iostream>
>
> using namespace boost::lambda;
>
> int main() {
>
> std::vector<int> b1;
> b1.push_back(1); b1.push_back(2);
>
> std::vector<int> b2;
> b2.push_back(3); b2.push_back(4); b2.push_back(5);
>
> std::vector<std::vector<int> > a;
> a.push_back(b1);
> a.push_back(b2);
>
> int sum = 0;
> std::for_each(a.begin(), a.end(),
> bind(ll::for_each(),
> bind(call_begin(), _1), bind(call_end(), _1),
> protect(sum += _1)));
>
> std::cout << "sum = " << sum << "\n";
> }
> // ------------------
>
>
>
>
> On Tue, 10 Dec 2002, Robin.Hu wrote:
>
> > Hi Boosters:
> >
> > In the document of boost::lambda (ar01s05.html#sect:nested_stl_algorithms),
> > it says:
> > ------------------>cited begin<-------------------
> > Some aid for common special cases can be provided though. The BLL defines two
> > helper function object classes, call_begin and call_end, which wrap a
> > call to the begin and, respectively, end functions of a container,
> > and return the const_iterator type of the container. With these
> > helper templates, the above code becomes:
> >
> > std::for_each(a.begin(), a.end(),
> > bind(ll::for_each(),
> > bind(call_begin(), _1), bind(call_end(), _1),
> > protect(sum += _1)));
> > ------------------->cited end<---------------------
> >
> > But I failed to compile this example with gcc 3.2 and vc 2003 beta.
> > I think the problem is, both struct call_begin and struct call_end dont
> > provide a result_type.
> >
> > [lambda/algorithm.hpp]
> > ------------------->cited begin<-------------------
> > #define CALL_MEMBER(X) \
> > struct call_##X { \
> > template <class Args> \
> > struct sig { \
> > typedef typename boost::remove_const< \
> > typename boost::tuples::element<1, Args>::type \
> > >::type::const_iterator type; \
> > }; \
> > \
> > template<class T> \
> > typename T::const_iterator \
> > operator()(const T& t) const \
> > { \
> > return t.X(); \
> > } \
> > };
> > ------------------->cited end<---------------------
> >
> > Is there anything I missed? And is there a possibel way to make these
> > call_xxx run?
> >
> >
>
> --
> --
> -- Jaakko Järvi email: jajarvi_at_[hidden]
> -- Post Doctoral Fellow phone: +1 (812) 855-3608
> -- Pervasive Technology Labs fax: +1 (812) 855-4829
> -- Indiana University, Bloomington
>
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
-- <huxw_at_[hidden]>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk