Questions tagged [boost-range]

Boost.Range is a C++ library containing a collection of concepts and utilities, range-based algorithms, as well as range adaptors that allow for efficient and expressive code.

Boost.Range is a C++ library containing a collection of concepts and utilities, range-based algorithms, as well as range adaptors that allow for efficient and expressive code.

Using Boost.Range inplace of the standard library alternatives results in more readable code and in many cases greater efficiency.

104 questions
4
votes
1 answer

C++: how to find max_element using boost::range?

I am trying to return an iterator to the largest element in a filtered range. Here is what I have so far: #include #include #include #include #include…
linuxfever
  • 3,763
  • 2
  • 19
  • 43
3
votes
1 answer

Combining boost range algorithms, eg. boost::copy and boost::remove_if

I am trying to write a complex list of algorithms that must be applied to a range sequence. I would like to nest many algorithms using a syntax similar to the following code. My only problem is that it won't compile. Any suggestions? bool…
Adrian
  • 90
  • 1
  • 7
3
votes
1 answer

Implementing a Boost range adaptor reversed_if

I regularly encounter situations in my code in which I would like to iterate over a range in direct or in reverse order depending on a runtime condition. This typically results in code like the following if (reverse) { using…
3
votes
2 answers

“use algorithms; don’t write code” for multi-step logic?

This question makes me think “don’t use an explicit loop at all! Use STL/Boost algorithms” but looking in detail, I note that there is an adjacent_difference, and accumulate and Boost has a zip somewhere, while (i
JDługosz
  • 5,592
  • 3
  • 24
  • 45
3
votes
1 answer

c++ boost ranges: any_range and transformed adaptor

I am trying to wrap a boost range that uses the boost transformed adapter into a boost any range, but this does not seem to work. I constructed a minimal example to illustrate. std::vector myInts = { 1,2,3,4,5…
3
votes
1 answer

Why is adl preferring the 'boost::range_detail::operator|' over the local 'operator|'?

I'm trying to write an operator| for my template class boo and everything works out fine until the template class is a boost range type - like in the example a boost::range::filter_range - adl prefers the…
TimW
  • 8,351
  • 1
  • 29
  • 33
3
votes
1 answer

boost::adaptor::filtered core dumps with boost::range_detail::default_constructible_unary_fn_wrapper "Assertion `m_impl' failed"

I get an assertion failure inside boost::range_detail::default_constructible_unary_fn_wrapper when I run this code. The assertion appears to be checking that the functor has been initialized inside the filter object. #include…
caps
  • 1,225
  • 14
  • 24
3
votes
1 answer

Custom range for boost::range library

I’m writing filter and map algorithms using boost::range library: template struct Converter { Converter(const Range& p_range) : m_range(p_range) {} template operator OutContainer() const { …
Yahoo
  • 63
  • 6
3
votes
2 answers

boost::adaptors::strided cannot be used after boost::adaptors::transformed?

The following does not compile on Visual Studio 2010: std::vector v; for (int i = 0; i < 10; ++i) v.push_back (i); struct TrivialTrafo { typedef int result_type; int operator () (int i) const { return 1; } }; auto x = v |…
JohnB
  • 13,315
  • 4
  • 38
  • 65
3
votes
1 answer

Filtered ranges, lambdas, and is_sorted

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…
akim
  • 8,255
  • 3
  • 44
  • 60
3
votes
2 answers

How to declare boost range adaptor (e.g. map_values)

Say I have class Value; class Key; class MyClass { private: std::map my_map; .... } Inside of MyClass methods I have a very convenient way to iterate through values of my_map by saying for( auto& value: my_map |…
LRaiz
  • 667
  • 7
  • 18
3
votes
1 answer

How do I use MFC CString with the boost string algorithm library

Preliminary note: string_algo works just fine with std::wstring and of course I can (and do) convert the CString object(s) to std::wstring first if and when I need an algorithm from string_algo. It would be really nice though if I could just drop in…
Martin Ba
  • 37,187
  • 33
  • 183
  • 337
3
votes
1 answer

Using boost range adaptors with a directory iterator range

Edit: I added some solutions below my question, based on Jonathan's answer I want to have a list of regular files with a certain name pattern in a given directory. I took one of the examples from boost.filesystem (boost 1.53) and modified it. Here…
Christoph
  • 1,040
  • 3
  • 14
  • 29
2
votes
1 answer

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

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::type…
2
votes
2 answers

How to generate a view of pairs from an array?

I have a C array of ints, and its size, i.e. int* arr, unsigned size. I want to have something like a view from it, which will have pairs of ints as elements. To clarify, the task is: I receive an array like [1,2,3,4] and I want a view, which will…
Nikita Vorobyev
  • 313
  • 2
  • 9