![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
indexedBoost , Chapter 1. Range 2.0 , Reference
DescriptionИндекс в пределах каждого возвращенного<
boost::range::index_value< typename boost::range_reference<decltype(rng)>::type, typename boost::range_difference<decltype(rng)>::type > Синопсис значения index_value выглядит следующим образом: template<class T, class Indexable=std::ptrdiff_t> class index_value : public boost::tuple<Indexable, T> { public: typedef ...unspecified... index_type; typedef ...unspecified... const_index_type; typedef ...unspecified... value_type; typedef ...unspecified... const_value_type; // ...unspecified... constructors index_type index(); const_index_type index() const; value_type value(); const_value_type value() const; };
#include <boost/range/adaptor/indexed.hpp> #include <boost/assign.hpp> #include <iterator> #include <iostream> #include <vector> int main(int argc, const char* argv[]) { using namespace boost::assign; using namespace boost::adaptors; std::vector<int> input; input += 10,20,30,40,50,60,70,80,90; for (const auto& element : input | indexed(0)) { std::cout << "Element = " << element.value() << " Index = " << element.index() << std::endl; } return 0; } Это позволит получить результат: Element = 10 Index = 0 Element = 20 Index = 1 Element = 30 Index = 2 Element = 40 Index = 3 Element = 50 Index = 4 Element = 60 Index = 5 Element = 70 Index = 6 Element = 80 Index = 7 Element = 90 Index = 8 Статья indexed раздела Chapter 1. Range 2.0 Reference может быть полезна для разработчиков на c++ и boost. Материалы статей собраны из открытых источников, владелец сайта не претендует на авторство. Там где авторство установить не удалось, материал подаётся без имени автора. В случае если Вы считаете, что Ваши права нарушены, пожалуйста, свяжитесь с владельцем сайта.
|
||||||||||||||||||||||
©KANSoftWare (разработка программного обеспечения, создание программ, создание интерактивных сайтов), 2007 |