boost-range

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:

boost multi_index_container and slow operator++

那年仲夏 提交于 2019-12-25 04:46:20
问题 It is follow-up question for this MIC question. When adding items to the vector of reference wrappers I spend about 80% of time inside ++ operator whatever iterating approach I choose. The query works as following VersionView getVersionData(int subdeliveryGroupId, int retargetingId, const std::wstring &flightName) const { VersionView versions; for (auto i = 0; i < 3; ++i) { for (auto j = 0; j < 3; ++j) { versions.insert(m_data.get<mvKey>().equal_range(boost::make_tuple(subdeliveryGroupId + i,

Unzip in C++ Range-v3 library

偶尔善良 提交于 2019-12-23 12:38:51
问题 Is it possible to unzip previously zipped vectors using the C++ Range-v3 library? I would expect it to behave similarly to Haskell's unzip function or Python's zip(*list). It would be convenient, for instance, when sorting a vector by values of another vector: using namespace ranges; std::vector<std::string> names {"john", "bob", "alice"}; std::vector<int> ages {32, 19, 35}; // zip names and ages auto zipped = view::zip(names, ages); // sort the zip by age sort(zipped, [](auto &&a, auto &&b)

Boost-range not working with C++1y init-capture mutable lambda

百般思念 提交于 2019-12-11 06:55:58
问题 I want to compute the element-wise difference of two vectors using Boost.Range and C++1y lambdas with init-capture . The simpler case of subtracting a fixed (i.e. the first) element of one vector works. However, when I try to compute the "vectorized difference" by increasing the iterator over the second range (and making the lambda mutable ), I get a compiler error. Sample code (note that I didn't use generalized lambdas so that both g++ 4.8 and Clang SVN can parse this code): #include

How do I boost::range::sort() a boost::transformed_range?

烈酒焚心 提交于 2019-12-11 06:15:42
问题 I want to get the unique elements from a vector<foo> based on a member of foo . I am using boost::adaptors::transform to select the member, then sorting, then using boost::adaptors::unique . I'm having trouble getting the sort step to work. Leaving aside the unique call for now, I've tried the below code on Coliru. #include <iostream> #include <string> #include <vector> #include <boost/range/adaptor/transformed.hpp> #include <boost/range/algorithm/sort.hpp> struct foo { foo(std::string a) :

Appending ranges in loop

馋奶兔 提交于 2019-12-11 03:52:32
问题 I would like to concatenate ranges returned by function into one big range.Consider following code: some_type_i_cant_figure_out bar() { typedef std::vector<int>::const_iterator iter; std::vector<int> aaa; /* fill some data into aaa*/ some_type_i_cant_figure_out cc; for (int i = 0; i < aaa.size(); ++i) { std::pair<iter, iter> bbb = foo(aaa, i); ccc = boost::join(ccc, bbb); } return ccc; } What I'm trying to achieve: The aaa vector is huge and foo may return quite big ranges. Of course I can

Filtered ranges, lambdas, and is_sorted

 ̄綄美尐妖づ 提交于 2019-12-11 02:44:37
问题 This is a stripped-down version of a problem I have with filtered iterators (so there's no point in asking me to rewrite it differently to avoid the filters). Weirdly enough, in the real code only is_sorted seems to the problem, other uses appear to work fine. #include <vector> #include <boost/range/adaptor/filtered.hpp> #include <boost/range/algorithm_ext/is_sorted.hpp> int main(int argc, const char* argv[]) { using namespace boost::adaptors; std::vector<int> all = {1,2,3,4,5,6,7,8,9}; auto

itertools.tee equivalent in Boost::Range?

元气小坏坏 提交于 2019-12-08 16:15:27
问题 Python's itertools has tee for n-plicating iterables: def tee(iterable, n=2): it = iter(iterable) deques = [collections.deque() for i in range(n)] def gen(mydeque): while True: if not mydeque: # when the local deque is empty newval = next(it) # fetch a new value and for d in deques: # load it to all the deques d.append(newval) yield mydeque.popleft() return tuple(gen(d) for d in deques) I couldn't find the equivalent in Boost::Range . Am I missing something or should I just roll my own? 回答1:

boost multi_index_container, range mutating algorithms and constness

拥有回忆 提交于 2019-12-07 18:32:37
问题 I'm using boost multi_index_container, which is queried by equal_range and the result returned from the function using range::join and boost::any_range The any_range Reference argument is defined as const reference to the type - must be const because of the multi_index_container nature, not quite sure about the reference. Example: typedef boost::any_range<TestData, boost::random_access_traversal_tag, const TestData &, std::ptrdiff_t> TestRange; Now what I need is to use mutating range

Custom range for boost::range library

血红的双手。 提交于 2019-12-07 15:59:00
问题 I’m writing filter and map algorithms using boost::range library: template <class Range> struct Converter { Converter(const Range& p_range) : m_range(p_range) {} template<class OutContainer> operator OutContainer() const { return {m_range.begin(), m_range.end()}; } private: Range m_range; }; template<class Range> Converter<Range> convert(const Range& p_range) { return {p_range}; } template<class Range, class Fun> auto map(Range&& p_range, Fun&& p_fun) { return convert(p_range | boost: