total noob help: LAMBDA with zip_iterator

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

total noob help: LAMBDA with zip_iterator

cablepuff
I have several questions that I asked earlier but never got an answer.

So I will start one by one..

a.) How do I use lambda with zip_iterator.  (assuming you have a zip_iterator of vector, list, map)?

Thats my first question...

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: total noob help: LAMBDA with zip_iterator

David Abrahams
"chun ping wang" <[hidden email]> writes:

> I have several questions that I asked earlier but never got an answer.
>
> So I will start one by one..
>
> a.) How do I use lambda with zip_iterator.  (assuming you have a
> zip_iterator of vector, list, map)?
>
> Thats my first question...

There are many possible answers.  What are you trying to accomplish
with lambda and zip_iterator?

--
Dave Abrahams
Boost Consulting
www.boost-consulting.com

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: total noob help: LAMBDA with zip_iterator

cablepuff
alright i am trying to stimulate the safety algorithm Operating system concepts seventh edition book. Note i haven't use static_assert yet. Basically i am trying to experiment on how boost can help replace low level concept code in which any language be it, php, perl, java ( i.e. replace of indexing if possible) can write simple algorithm whether to increase readability, maintainbility or anything. All these are just experimental code. Thank you very much.The problem with python iterators is that you can't reassign iteration values in list.

template <class T, int N>
struct DimArray
{
    typedef typename boost::multi_array<T, N> ndimarr;
    typedef typename boost::multi_array<T, N>::size_type size;
};
 
   /******************************************************
    * check to see if the current status is safe         *
    * @return true if state is safe and false otherwise  *
    * @param Max is n x m matrix of maximum resources    *
    * @param Alloc is n x m matrix of allocated resources*
    * @param Need is n x m matrix of needed resources    *
    * @param Available is m size avaliable resource vec  *
    * @templateparam: T any numeric type (int, double, float)     *
    * @templateparam: CONT any container type of std::allocator *
    *****************************************************/
template <typename T,
           template <
                     typename ELEM,
                     typename = std::allocator<ELEM>
           >
           class CONT
>
bool DLA::isSafe(const typename DimArray<T, 2>::ndimarr& MAX,
               const typename DimArray<T, 2>::ndimarr& Alloc,
               const typename DimArray<T, 2>::ndimarr& Need,
               const typename DimArray<T, 1>::ndimarr& Available)
{
    using namespace boost::lambda;
   BOOST_STATIC_ASSERT(boost::is_integral<T>::value);
    typename DimArray<T, 1>::ndimarr Work(Available);
    typedef typename DimArray<T, 2>::size TDS;
    const TDS outer_sz(MAX.size());
    CONT<bool> Finish(outer_sz, false);
    typedef typename CONT<bool>::const_iterator ContIter;
    typedef typename DimArray<T, 2>::ndimarr::const_iterator MultIter;
    typedef typename DimArray<T, 1>::ndimarr::const_iterator OneIter;
    ContIter iter;
 MultIter beg1(Need.begin());
    MultIter beg2(Alloc.begin());
    MultIter end1(Need.end());
    MultIter end2(Alloc.end());
 ContIter beg3(Finish.begin());
 ContIter end3(Finish.end ());
    TDS ind(0);
    while ((iter = std::find(Finish.begin(), Finish.end(), false)) != Finish.end())
    {
  /* 
    new code
  std::for_each(
           // iterate through (Need, Alloc, Finish).
            boost::make_zip_iterator(boost::make_tuple(beg1, beg2, beg3)),
            boost::make_zip_iterator(boost::make_tuple(end1, end2, end3)),
           (
               Parts where i wish to use lambda for abstraction .
                Assume:
                  _1 = Need[i],
                  _2 = Alloc[i],
                  _3 = Finish[i],
                 if (_1 == false && _3 <= Work)  
                { 
                        _3 = true;
                        Work += _2;
                 }
             ++var(ind)
          )
    );
   */
   /*
    Old code
     for (int i = distance(Finish.begin(), iter); i < Finish.size(); ++i)
          {
              if (Finish[i] == false && ((typename DimArray<T, 1>::ndimarr) Need[i]) <= Work)
              {
                 Finish[i] = true;
                 Work = array_add<T>(Work, ((typename DimArray<T, 1>::ndimarr)Alloc[i]));
                 std::cout << "p[" << i << "]\n";
              }
          }
      */
    }
    return (std::binary_search(Finish.begin(), Finish.end(), false))
          ? false : true;
}

 
On 4/7/06, David Abrahams <[hidden email]> wrote:
"chun ping wang" <[hidden email]> writes:

> I have several questions that I asked earlier but never got an answer.
>
> So I will start one by one..
>
> a.) How do I use lambda with zip_iterator.  (assuming you have a
> zip_iterator of vector, list, map)?
>
> Thats my first question...

There are many possible answers.  What are you trying to accomplish
with lambda and zip_iterator?

--
Dave Abrahams
Boost Consulting
www.boost-consulting.com

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users


_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: total noob help: LAMBDA with zip_iterator

David Abrahams
"chun ping wang" <[hidden email]> writes:

>   std::for_each(
>            // iterate through (Need, Alloc, Finish).
>             boost::make_zip_iterator(boost::make_tuple(beg1, beg2, beg3)),
>             boost::make_zip_iterator(boost::make_tuple(end1, end2, end3)),
>            (
>                Parts where i wish to use lambda for abstraction .
>                 Assume:
>                   _1 = Need[i],
>                   _2 = Alloc[i],
>                   _3 = Finish[i],
>                  if (_1 == false && _3 <= Work)
>                 {
>                         _3 = true;
>                         Work += _2;
>                  }
>              ++var(ind)
>           )
>     );

Ah.  What you want is a way to wrap a lambda expression so that it accepts
a single tuple argument and exposes each element of the tuple to the
wrapped lambda expression as a separate argument.  It should be
possible, but we'll have to ask Jaakko and Gary for details.  I'm
pretty sure it's possible using Fusion and Spirit-2, but you'd need a
different version of zip_iterator.hpp (one that's checked in on a
branch of Boost's CVS).

--
Dave Abrahams
Boost Consulting
www.boost-consulting.com

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users