我有以下代码:
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()));
如果我想要decltype
返回值,而不是将其存储在 an 中,auto
我可以将它存储在decltype
任何boost::make_zip_iterator
返回的 a 中。该代码是什么样的?
我努力了:
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()));
但这甚至还没有接近工作。最后,如果我想迭代zipBidsAsks
并获得每个<0>
, <1>
. 这是怎么做的?
访问代码现在给出一个错误:
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)’|