升压decltype :: make_zip_iterator? [英] decltype of boost::make_zip_iterator?

查看:163
本文介绍了升压decltype :: make_zip_iterator?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code:

 的std ::矢量< PriceQuote,TBB :: scalable_allocator< PriceQuote> > cBids(MAXSIZE);
的std ::矢量< PriceQuote,TBB :: scalable_allocator< PriceQuote> >木桶(MAXSIZE);汽车zipBidsAsks =的boost :: make_zip_iterator(升压:: make_tuple(cBids.begin(),cAsks.begin()));

如果我想 decltype 的返回值,这样,而不是将其存储在一个汽车我可以储存它在一个 decltype 任何的boost :: make_zip_iterator 的回报。这是什么code样子?

我曾尝试:

 的typedef decltype(升压:: make_zip_iterator(性病::矢量< PriceQuote>中的std ::矢量<&PriceQuote GT;))zipper_type;//类型由zipper_type:迭代简称
的typedef的std :: iterator_traits< zipper_type:迭代> :: value_type的zipped_type; zipped_type zipBidsAsks =的boost :: make_zip_iterator(升压:: make_tuple(cBids.begin(),cAsks.begin()));

但是,这并不甚至接近正常工作。最后,如​​果我想遍历 zipBidsAsks 并获得每个&℃的GT; &LT 1 GT; 。如何做呢?

访问code现在给出了一个错误:

 结构PriceBookEventData
{
    timeval中TS;
    无符号总计TOTALSIZE;
    无符号MAXSIZE;
    的typedef decltype
    (
         提高:: make_zip_iterator(升压::元组LT;的std ::矢量<&PriceQuote GT; ::迭代器,
                                               的std ::矢量<&PriceQuote GT; ::迭代器>())
    )zipper_type;     zipper_type zipBidsAsks;
};无效AGUI :: HandlePriceBookChange(常量PriceBookEventData pbed)
{
INT K = 0;而(0!= stop--)
{
    PriceQuote PQB =提振::获得℃的>(pbed.zipBidsAsks [K]);
    PriceQuote PQA =提振::获得< 1 GT;(pbed.zipBidsAsks [K]);
/data/cbworkspace/AGUI/AGUI.cpp|101|error:呼叫没有匹配函数‘get(boost::detail::operator_brackets_result<boost::zip_iterator<boost::tuples::tuple<__gnu_cxx::__normal_iterator<PriceQuote*,的std ::矢量&lt;&PriceQuote GT; &gt;中__gnu_cxx :: __ normal_iterator&LT; PriceQuote *的std ::矢量&lt;&PriceQuote GT; &GT; &GT; &gt;中的boost ::元组::利弊&LT; PriceQuote&放;,提振::元组::利弊&LT; PriceQuote&放;,提振::元组:: null_type&GT; &gt;中的boost ::元组::利弊&LT; PriceQuote&放;,提振::元组::利弊&LT; PriceQuote&放;,提振::元组:: null_type&GT; &GT; &GT; ::型)|


解决方案

我不知道你为什么要使用 decltype 而不是<$ C弄清楚类型$ C>汽车,后者是专门为像这样1案件设计。使用 decltype 反而是累赘。

您已经接近与你试了一下,除了你给的boost :: make_zip_iterator 一对,而不是载体,元组矢量interators的。

试试这个

 的typedef decltype(
  提高:: make_zip_iterator(
    提高::元组LT;
      的std ::矢量&lt;&PriceQuote GT; ::迭代器,
      的std ::矢量&lt;&PriceQuote GT; ::迭代器&GT;()
  )
)zipper_type;

至于遍历拉链迭代器,这里有一个简单的例子:

 的#include&LT;&iostream的GT;
#包括LT&;升压/迭代器/ zip_iterator.hpp&GT;
#包括LT&;升压/元组/ tuple.hpp&GT;
#包括LT&;矢量&GT;诠释的main()
{
    的std ::矢量&lt;&INT GT; V1 {1,2,3,4},{V2 10,20,30,40};    的std :: for_each的(
        提高:: make_zip_iterator(升压:: make_tuple(v1.begin(),v2.begin()))
        提高:: make_zip_iterator(升压:: make_tuple(v1.end(),v2.end()))
        [](升压::元组LT; INT,INT&GT;常量和放大器; TUP){
            性病::法院
              &LT;&LT;提高::获得℃的&GT;(TUP)
              &LT;&LT; ,
              &LT;&LT;提高::获得&LT; 1 GT;(TUP)
              &LT;&LT;的std :: ENDL;
        }
    );
}

输出:

  1,10
2,20
3,30
4,40

I have the following code:

std::vector<PriceQuote, tbb::scalable_allocator<PriceQuote> > cBids(maxSize);
std::vector<PriceQuote, tbb::scalable_allocator<PriceQuote> > cAsks(maxSize);

auto zipBidsAsks = boost::make_zip_iterator(boost::make_tuple(cBids.begin(), cAsks.begin()));

If I wanted to decltype the return value so that instead of storing it in an auto I can store it in a decltype of whatever boost::make_zip_iterator returns. What does that code look like?

I have tried:

typedef decltype(boost::make_zip_iterator(std::vector<PriceQuote>, std::vector<PriceQuote>)) zipper_type;

// type referred to by zipper_type::iterator
typedef std::iterator_traits<zipper_type::iterator>::value_type zipped_type;

 zipped_type zipBidsAsks = boost::make_zip_iterator(boost::make_tuple(cBids.begin(), cAsks.begin()));

But that doesn't even come close to working. Finally, if I want to iterate over zipBidsAsks and get each <0>, <1>. How is that done?

The access code now gives an error:

    struct PriceBookEventData
{
    timeval ts;
    unsigned totalSize;
    unsigned maxSize;


    typedef decltype
    (
         boost::make_zip_iterator(boost::tuple<std::vector<PriceQuote>::iterator,
                                               std::vector<PriceQuote>::iterator>())
    ) zipper_type;

     zipper_type zipBidsAsks;
};

void AGUI::HandlePriceBookChange(const PriceBookEventData pbed)
{
int k = 0;

while(0 != stop--)
{
    PriceQuote pqb = boost::get<0>(pbed.zipBidsAsks[k]);
    PriceQuote pqa = boost::get<1>(pbed.zipBidsAsks[k]);


/data/cbworkspace/AGUI/AGUI.cpp|101|error: no matching function for call to ‘get(boost::detail::operator_brackets_result<boost::zip_iterator<boost::tuples::tuple<__gnu_cxx::__normal_iterator<PriceQuote*, std::vector<PriceQuote> >, __gnu_cxx::__normal_iterator<PriceQuote*, std::vector<PriceQuote> > > >, boost::tuples::cons<PriceQuote&, boost::tuples::cons<PriceQuote&, boost::tuples::null_type> >, boost::tuples::cons<PriceQuote&, boost::tuples::cons<PriceQuote&, boost::tuples::null_type> > >::type)’|

解决方案

I'm not sure why you want to figure out the type using decltype instead of auto, the latter was designed specifically for cases like this one. Using decltype instead is cumbersome.

You were close with what you tried, except you gave boost::make_zip_iterator a pair of vectors, instead of a tuple of vector interators.

Try this instead

typedef decltype(
  boost::make_zip_iterator(
    boost::tuple<
      std::vector<PriceQuote>::iterator, 
      std::vector<PriceQuote>::iterator>()
  ) 
) zipper_type;

As for iterating over the zip iterator, here's a simple example:

#include <iostream>
#include <boost/iterator/zip_iterator.hpp>
#include <boost/tuple/tuple.hpp>
#include <vector>

int main()
{
    std::vector<int> v1{1,2,3,4}, v2{10,20,30,40};

    std::for_each(
        boost::make_zip_iterator(boost::make_tuple(v1.begin(), v2.begin())),
        boost::make_zip_iterator(boost::make_tuple(v1.end(), v2.end())),
        []( boost::tuple<int, int> const& tup ) {
            std::cout 
              << boost::get<0>(tup) 
              << ", " 
              << boost::get<1>(tup) 
              << std::endl;
        }
    );
}

Output:

1, 10
2, 20
3, 30
4, 40

这篇关于升压decltype :: make_zip_iterator?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆