c++ - decltype of boost::make_zip_iterator? -


i have 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 wanted decltype return value instead of storing in auto can store in decltype of whatever boost::make_zip_iterator returns. code like?

i have tried:

typedef decltype(boost::make_zip_iterator(std::vector<pricequote>, std::vector<pricequote>)) zipper_type;  // type referred 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 doesn't come close working. finally, if want iterate on zipbidsasks , each <0>, <1>. how done?

the access code gives 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 call ‘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 want figure out type using decltype instead of auto, latter designed cases one. using decltype instead cumbersome.

you close tried, except gave boost::make_zip_iterator pair of vectors, instead of tuple of vector interators.

try instead

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

as iterating on zip iterator, here's 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 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -