boost-iterators

How to convert a single object to a boost::any_range?

岁酱吖の 提交于 2021-01-28 04:56:13
问题 I'm trying to create and return a boost:any_range that contains only one object (I don't know if that's the core problem) but I get the following errors: error C2893: Failed to specialize function template 'range_iterator<C,void>::type boost::range_adl_barrier::begin(T &)' note: With the following template arguments: note: 'T=const WrappedRange' error C2672: 'end': no matching overloaded function found error C2893: Failed to specialize function template 'range_iterator<C,void>::type boost:

In the Boost Graph Library, why does adding an edge invalidate Edge iterators (and other questions)?

冷暖自知 提交于 2020-01-04 05:17:19
问题 A few questions about the chart in the BGL documentation labeled "Summary of Descriptor and Iterator Invalidation": Why does adding an edge invalidate the edge and adjacency iterators; why isn't every column of the add_edge() row "OK"? Wouldn't the in/out edge lists simply be appended? Why does removing an edge only invalidate an edge iterator if the graph is directed; why is the second to last column in the second row not simply "EL=vecS"? In the undirected graph case wouldn't removing an

Skipping iterator

拥有回忆 提交于 2019-12-17 16:56:09
问题 I have a sequence of values that I'd like to pass to a function that takes a (iterator begin, iterator end) pair. However, I only want every second element in the original sequence to be processed. Is there a nice way using Standard-Lib/Boost to create an iterator facade that will allow me to pass in the original sequence? I figured something simple like this would already be in the boost iterators or range libraries, but I didn't find anything. Or am I missing another completely obvious way

boost::range::detail::any_iterator doesn't play well with boost::zip_iterator

拥有回忆 提交于 2019-12-13 17:09:12
问题 Consider the following code: #include <boost/iterator/zip_iterator.hpp> #include <boost/range/detail/any_iterator.hpp> #include <boost/tuple/tuple.hpp> #include <iostream> #include <vector> typedef boost::range_detail::any_iterator< boost::tuple<int &, char &>, boost::random_access_traversal_tag, boost::tuple<int &, char &> &, std::ptrdiff_t > IntCharIterator; int main() { std::vector<int> v1 = {1, 2, 3, 4, 5}; std::vector<char> v2 = {'a', 'b', 'c', 'd', 'e'}; auto it = IntCharIterator(boost:

reading a file of key-value pairs in to a std::map

十年热恋 提交于 2019-12-12 12:05:10
问题 I have a Visual Studio 2008 C++03 project where I would like to read a file of key-value pairs in to a std::map. To do that I've created an istreambuf_pair_iterator as below: typedef std::map< std::string, std::string > Properties; class istreambuf_pair_iterator : public boost::iterator_adaptor< istreambuf_pair_iterator, std::pair< std::string, std::string >*, boost::use_default, boost::forward_traversal_tag > { public: istreambuf_pair_iterator() : sb_( 0 ) { }; explicit istreambuf_pair

How to expose C++ classes with const_iterator

陌路散爱 提交于 2019-12-11 06:38:18
问题 I am using Boost.Python to expose a 3rd party C++ API. A header file I've come to declares an iterable class (has begin and end methods), and a custom iterator class with which to do the iteration:- // File: data.hpp #include <utility> // for std::pair #include <cstring> // for size_t namespace notmylib { // forward declaration class DataIterator; // Storage for arbitrary data class Data { public: Data(void); virtual ~Data(void); // ... typedef DataIterator const_iterator; const_iterator

Defining a proxy-based OutputIterator in terms of boost::iterator_facade

风流意气都作罢 提交于 2019-12-08 14:07:19
问题 I wrote this C++17 code and expected it to work out of the box. class putc_iterator : public boost::iterator_facade< putc_iterator, void, std::output_iterator_tag > { friend class boost::iterator_core_access; struct proxy { void operator= (char ch) { putc(ch, stdout); } }; auto dereference() const { return proxy{}; } void increment() {} bool equal(const putc_iterator&) const { return false; } }; I'm trying to match the behavior of all the standard OutputIterators by setting my iterator's

transform_iterator compile problem

一笑奈何 提交于 2019-12-01 19:40:58
问题 HI, I don't like posting compile problems, but I really can't figure this one out. Using this code: #include <map> #include <boost/iterator/transform_iterator.hpp> using namespace std; template <typename K, typename V> struct get_value { const V& operator ()(std::pair<K, V> const& p) { return p.second; } }; class test { typedef map<int, float> TMap; TMap mymap; public: typedef get_value<TMap::key_type, TMap::value_type> F; typedef boost::transform_iterator<F, TMap::iterator> transform

Skipping iterator

£可爱£侵袭症+ 提交于 2019-11-28 01:50:46
I have a sequence of values that I'd like to pass to a function that takes a (iterator begin, iterator end) pair. However, I only want every second element in the original sequence to be processed. Is there a nice way using Standard-Lib/Boost to create an iterator facade that will allow me to pass in the original sequence? I figured something simple like this would already be in the boost iterators or range libraries, but I didn't find anything. Or am I missing another completely obvious way to do this? Of course, I know I always have the option of copying the values to another sequence, but