4

I understood how to create my own range-v3 views using view-facade, but now I would like to create my own container so I can use in-place-mutating actions:

MyContainer<ItemType> list = createList();
list |= ranges::actions::transform(&someMappingFunction);

Unfortunately, there seems to be no simple helper like a container-facade and my C++ skills are not mad enough yet to understand the range-v3 source by just reading it. Which interface does my container need to implement, or what does it need to be derived from?

Thanks for any hints!

Anselm Eickhoff
  • 589
  • 2
  • 5
  • 14

1 Answers1

2

From the perspective of range-v3, a Range is a Container if begin on a mutable instance returns a different type than on a const instance, or if is_view<T>::value is false. The actions often require additional capabilities. For instance, many require cont.insert(pos, val) for inserting value val into container cont at position pos. Some require cont.erase(from, to) for removing elements denoted by the range [from,to). Apologies for the lack of documentation. HTH.

Eric Niebler
  • 5,927
  • 2
  • 29
  • 43
  • Thank you, that makes sense, but I guess it's just too difficult for me to see the general interface of a range in the template-heavy source of range-v3. Could you please sketch in your answer a very minimal implementation of a dummy range/container that just shows what has to be overridden to make it work? Or is there something explicit like this already hidden in the range-v3 source, tests, examples or elsewhere? Thanks again – Anselm Eickhoff Feb 22 '16 at 20:15
  • Wait... is it true that I can just implement a STL compatible container + iterator and it'll work as an input and output range? – Anselm Eickhoff Feb 22 '16 at 21:49
  • Your container should have const and non-const begin/end, and (depending on what you want to do) an insert member that takes a position and a value, and an erase member that takes two iterators. That should make most (all?) of the actions work. I can't check right now, sorry. – Eric Niebler Feb 22 '16 at 21:58