Best way to put N ranges into a new container?

I was originally contemplating writing something that took some number of Range arguments and push_back'ed onto a container. Where all of them are Random Access Ranges, it can count the elements first and reserve once. Otherwise, it just concats one range at a time. Maybe could be a bit smarter, but you get the idea. But reading through the Range docs, I'm wondering now if a better approach would be a Range Adaptor that could make a concatenated "view" (to use MPL's terminology) of all of the components put together. Does something like that already exist? Thanks, --John (footer not my idea) TradeStation Group, Inc. is a publicly-traded holding company (NASDAQ GS: TRAD) of three operating subsidiaries, TradeStation Securities, Inc. (Member NYSE, FINRA, SIPC and NFA), TradeStation Technologies, Inc., a trading software and subscription company, and TradeStation Europe Limited, a United Kingdom, FSA-authorized introducing brokerage firm. None of these companies provides trading or investment advice, recommendations or endorsements of any kind. The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.

Le 06/07/2010 22:49, John Dlugosz a écrit :
I was originally contemplating writing something that took some number of Range arguments and push_back'ed onto a container. Where all of them are Random Access Ranges, it can count the elements first and reserve once. Otherwise, it just concats one range at a time. Maybe could be a bit smarter, but you get the idea.
But reading through the Range docs, I'm wondering now if a better approach would be a Range Adaptor that could make a concatenated "view" (to use MPL's terminology) of all of the components put together.
Does something like that already exist?
Yes, there is a join_iterator, joined_range, and a join function.

Does something like that already exist?
Yes, there is a join_iterator, joined_range, and a join function.
_______________________________________________
After pondering something like join(join(R1,R2),R3), I realized that the whole idea, while it would make functional programming guys smile, is inefficient. Iterating the joined range and copying one element at a time, with overhead to look for boundaries, will prevent the container's optimized push_back from being called with a range of contiguous memory of trivial items. So, I really want something that will call that form for the ranges. Now I'm thinking of a metaprogram like used for matrix math, to collect the N-ary concats and then apply them when the final thing is converted to a vector. Really, I'd like an "Assign" that uses such techniques instead of throwing everything into a deque and then copying it. --John TradeStation Group, Inc. is a publicly-traded holding company (NASDAQ GS: TRAD) of three operating subsidiaries, TradeStation Securities, Inc. (Member NYSE, FINRA, SIPC and NFA), TradeStation Technologies, Inc., a trading software and subscription company, and TradeStation Europe Limited, a United Kingdom, FSA-authorized introducing brokerage firm. None of these companies provides trading or investment advice, recommendations or endorsements of any kind. The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.

Le 07/07/2010 17:36, John Dlugosz a écrit :
After pondering something like join(join(R1,R2),R3), I realized that the whole idea, while it would make functional programming guys smile, is inefficient. Iterating the joined range and copying one element at a time, with overhead to look for boundaries, will prevent the container's optimized push_back from being called with a range of contiguous memory of trivial items.
So, I really want something that will call that form for the ranges. Now I'm thinking of a metaprogram like used for matrix math, to collect the N-ary concats and then apply them when the final thing is converted to a vector.
Really, I'd like an "Assign" that uses such techniques instead of throwing everything into a deque and then copying it.
The constructor of vector and its assign member function are already optimized to exploit random access iterators. Note however that a joined range of random access ranges doesn't know that every joined range is the same size, so its random access features are a bit slow.

The constructor of vector and its assign member function are already optimized to exploit random access iterators.
I would hope that is the case (for Dinkumware via Microsoft), and that it would be rather efficient for other cases where it can be relaxed, and going down to a single memcpy is the most extreme case. So, a lazy evaluator would combine cat(R1)(R2)(R3) into a single object that has an implicit conversion to vector, which works by creating a vector and hoping for RVO. That function's body can look at the total size and reserve it, then append each range in turn. I'm hoping/supposing that the natural way to append to a vector, which seems to be vector<T>::insert with Where being end(), is also optimized suitably. And, in terms of what I'm planning, that Boost.Range's natural way of appending a range to a vector calls that.
Note however that a joined range of random access ranges doesn't know that every joined range is the same size, so its random access features are a bit slow.
Makes sense. --John TradeStation Group, Inc. is a publicly-traded holding company (NASDAQ GS: TRAD) of three operating subsidiaries, TradeStation Securities, Inc. (Member NYSE, FINRA, SIPC and NFA), TradeStation Technologies, Inc., a trading software and subscription company, and TradeStation Europe Limited, a United Kingdom, FSA-authorized introducing brokerage firm. None of these companies provides trading or investment advice, recommendations or endorsements of any kind. The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.
participants (2)
-
John Dlugosz
-
Mathias Gaunard