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
6
votes
3 answers

Range-based for loop with boost::adaptor::indexed

The C++11 range-based for loop dereferences the iterator. Does that mean that it makes no sense to use it with boost::adaptors::indexed? Example: boost::counting_range numbers(10,20); for(auto i : numbers | indexed(0)) { cout << "number = " i …
gnzlbg
  • 7,135
  • 5
  • 53
  • 106
5
votes
2 answers

Boost any_range vs. "canonical form" - what is the latter?

Boost's any_range documentation says the following: Despite the underlying any_iterator being the fastest available implementation, the performance overhead of any_range is still appreciable due to the cost of virtual function calls required to…
paperjam
  • 8,321
  • 12
  • 53
  • 79
5
votes
1 answer

boost range adaptor that makes a collection

I want to write a boost adaptor to put at the end of a chain of adaptors to create a collection, like this: set s = input | filtered(...) | transformed(...) | to_set; Using Method 3.1 I wrote the code below which seems to work as…
Jay Bazuzi
  • 45,157
  • 15
  • 111
  • 168
5
votes
1 answer

Sorting Range-v3-zipped containers - can I unzip?

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…
Floop
  • 451
  • 4
  • 10
5
votes
2 answers

Metafunction to test whether object is compatible with boost range

Is there, or how would you write, a metafunction class that tests whether a class is compatible with boost::range? I want to use the boost::enable idiom, something like template Constructor::Constructor(const T& t,…
pythonic metaphor
  • 10,296
  • 18
  • 68
  • 110
5
votes
2 answers

Negate boost range filtered adaptor

Is it possible/achievable to negate a boost filtered adaptor, e.g. std::vector v = {1, 2, 3, 4, 5}; for(auto i : v | !filtered(is_even)) std::cout << i << std::endl; // prints 1,3,5 instead of doing the negation inside the lambda…
gnzlbg
  • 7,135
  • 5
  • 53
  • 106
4
votes
1 answer

How to create a Boost.Range that hides multiple layers of vectors and exposes it as a single Range?

I have a legacy class hierarchy which I can not modify. Because of requirements of an external library, I need to define Boost.Ranges for the Line and Ring, where both only expose the points in a single run (i.e. it should, both for Line and Ring,…
meastp
  • 682
  • 1
  • 7
  • 15
4
votes
1 answer

How to pass boost ranges to a function that accepts any_range

I am trying to write a class function which accepts boost::any_range which is a double-random access range. My purpose is to be able to pass any kind of that range to the function which can be an std::vector, std::deque, or a boost range. The code…
mecitsari
  • 65
  • 5
4
votes
1 answer

How can I make my container compatible with boost::range?

I'm rolling a custom, standard-like container and I'd like to have it compatible with the boost::range library. So far it works with all the STL algorithms and it also satisfies the…
4
votes
1 answer

I've written C++ code to treat boost::optional as a range but it doesn't compile

I wish to treat boost::optional as a container that can have zero or one elements in it. Logically I should be able to create an iterator to the container and use boost::for_each on it as well. My attempt is below but it fails to compile. I have…
bradgonesurfing
  • 30,949
  • 17
  • 114
  • 217
4
votes
1 answer

How to encapsulate custom iterator in function using boost-range

Lately I was using boost-range to create ranges over elements satisfying certain criteria. In all cases I'm using the same kind of filtered range all the time, so that I tried to encapsulate this behaviour in an external function. This was the…
Aleph0
  • 5,816
  • 4
  • 29
  • 80
4
votes
1 answer

Could range-based algorithm be fully independent of (and yet optimized for any) container type?

I was wondering if boost::range or range_v3 will reconciliate free functions and member functions in a similar way that std::begin reconciliates STL containers and C-like arrays (in terms of coding genericity I mean)? More particularly it would be…
4
votes
1 answer

Is there and neat equivalent to view a member function/variable?

Streams library has a neat map function to view a range by a member function. Is there any equivalent view in Range-V3? Would view::transform be the only option?
Viktor Sehr
  • 12,825
  • 5
  • 58
  • 90
4
votes
1 answer

value_type error when using STL containers with boost range adaptors

I've been trying to understand the use of boost range adaptors but all the working examples I have found only use STL containers with primitive types such as std::list and trying to use my own classes makes everything fall apart. #define…
sjdowling
  • 2,994
  • 2
  • 21
  • 31
4
votes
1 answer

Is boost Range library going to be part of next C++ standard?

I am trying to decide if I can start using Range based algorithms in the code. If it is more likely for it to be part of c++ standard, I can use it from boost in new code. Though it looks much better than iterators, it might make it difficult for…
balki
  • 26,394
  • 30
  • 105
  • 151