Boost logo

Boost Users :

From: chun ping wang (cablepuff_at_[hidden])
Date: 2006-04-15 21:38:57


k ignore hte previous example..i figure out a way around that using
BOOST_FOREACH....

Operator- version 1 works.
template <typename T,
         template <typename ELEM, typename = std::allocator<ELEM> >
         class CONT
>
CONT<T> operator-(CONT<T> arr1, CONT<T> arr2)
{
   using namespace boost::lambda;
   typedef typename CONT<T>::size_type sz;
   const sz arr1Size(arr1.size());
   const sz arr2Size(arr2.size());
   BOOST_STATIC_ASSERT(arr1Size == arr2Size);
   std::transform(arr1.begin(), arr1.end(), arr2.begin(), arr1.end(), _1 -=
_2);
   return arr1;
}

operator version 2: does not work.
template <typename T,
         template <typename ELEM, typename = std::allocator<ELEM> >
         class CONT
>
CONT<CONT<T> > operator-(CONT<CONT<T> > arr1, CONT<CONT<T> > arr2)
{
      using namespace boost::lambda;
      std::transform(arr1.begin(), arr1.end(), arr2.begin(), arr1.end(),
      protect(_1 - _2));
      return arr1;
}

Heres hte error i get.
826 C:\Dev-Cpp\include\c++\3.4.2\bits\stl_algo.h no match for 'operator=' in
'(&__result)->__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator*
[with _Iterator = std::vector<long int, std::allocator<long int> >*,
_Container = std::vector<std::vector<long int, std::allocator<long int> >,
std::allocator<std::vector<long int, std::allocator<long int> > > >]() =
boost::lambda::lambda_functor<Base>::operator()(A&, B&) const [with A =
std::vector<long int, std::allocator<long int> >, B = std::vector<long int,
std::allocator<long int> >, T =
boost::lambda::lambda_functor_base<boost::lambda::protect_action,
boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::arithmetic_action<boost::lambda::minus_action>,
boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::placeholder<1>
>, boost::lambda::lambda_functor<boost::lambda::placeholder<2> >,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type> > >,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type> >](((std::vector<long int, std::allocator<long
int> >&)(+(&__first1)->__gnu_cxx::__normal_iterator<_Iterator,
_Container>::operator* [with _Iterator = std::vector<long int,
std::allocator<long int> >*, _Container = std::vector<std::vector<long int,
std::allocator<long int> >, std::allocator<std::vector<long int,
std::allocator<long int> > > >]())), ((std::vector<long int,
std::allocator<long int>
>&)(+(&__first2)->__gnu_cxx::__normal_iterator<_Iterator,
_Container>::operator* [with _Iterator = std::vector<long int,
std::allocator<long int> >*, _Container = std::vector<std::vector<long int,
std::allocator<long int> >, std::allocator<std::vector<long int,
std::allocator<long int> > > >]())))'

 note C:\Dev-Cpp\include\c++\3.4.2\bits\vector.tcc:131 candidates are:
std::vector<T, Allocator>& std::vector<T, Allocator>::operator=(const
std::vector<T, Allocator>&) [with _Tp = long int, _Alloc =
std::allocator<long int>]

anyone care to explain how to fix these errors? Thanks.

On 4/14/06, chun ping wang <cablepuff_at_[hidden]> wrote:
>
> For some reason this thing don't work. I want to print a container of
> container.....
>
>
>
> #ifndef ARRAY_OPERATION_HPP
> #define ARRAY_OPERATION_HPP
> #include <iostream>
> #include <boost/lambda/lambda.hpp>
>
> template <typename T,
> template <
> typename ELEM,
> typename = std::allocator<ELEM>
> >
> class CONT
> >
> void print_array(const CONT<T>& array)
> {
> using namespace boost::lambda;
> std::for_each(array.begin(), array.end(), std::cout << _1 << " ");
> }
>
> template <typename T,
> template <
> typename ELEM,
> typename = std::allocator<ELEM>
> >
> class CONT
> >
> void print_2darray (const CONT<CONT<T> >& array)
> {
> using namespace boost::lambda;
> CONT<T> temp;
> std::for_each(array.begin(), array.end(),
> bind<T, CONT>(print_array<T, CONT>(), _1)
> );
> }
>
> #endif /* ARRAY_OPERATION_HPP */
>
> if i have std::list<std::list<double> > lOflDouble
>
> // insert some value in here.
>
> print_2darray<double>(lOflDouble);
>
> /*
> 30 C:\cs classes\cs540\c++\ContainerOperation.hpp no matching function for
> call to `print_array()'
> */
>
>
> On 4/14/06, David Abrahams <dave_at_[hidden]> wrote:
> >
> > "chun ping wang" <cablepuff_at_[hidden]> writes:
> >
> > > Heres a simple question, that i want to do.
> > >
> > > Lets say you have a function call void f(double);
> > >
> > > and then you want to apply f to each argument inside vector<double> a;
> > >
> > > for_each(a.begin(), a.end(), f(_1));
> > >
> > > // the example above isn't possible..is there a simple way to do
> > > this?
> >
> > for_each(a.begin(), a.end(), bind(f, _1));
> >
> > HTH,
> >
> > --
> > Dave Abrahams
> > Boost Consulting
> > www.boost-consulting.com
> >
> > _______________________________________________
> > Boost-users mailing list
> > Boost-users_at_[hidden]
> > http://lists.boost.org/mailman/listinfo.cgi/boost-users
> >
>
>



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