Is there something like shared_array<T> but with iterators?
I am doing signal processing, and in order to avoid data copies I need something that: 1) can adopt a buffer of data (e.g. take ownership of a T*) 2) Release that buffer via an appropriate method (e.g. take a deallocator object). 3) Provide operator[] over that buffer 4) provide shared ownership semantics So far, that's shared_array<> to a T [sic] However, I need one more thing: 5) provide iterator support (begin(), end(), cbegin(), cend()) The current shared_array<> doesn't provide that - is there anything else that does?
On Oct 14, 2014, at 5:00 PM, david.hagood@gmail.com wrote:
I am doing signal processing, and in order to avoid data copies I need something that: 1) can adopt a buffer of data (e.g. take ownership of a T*) 2) Release that buffer via an appropriate method (e.g. take a deallocator object). 3) Provide operator[] over that buffer 4) provide shared ownership semantics
So far, that's shared_array<> to a T [sic]
However, I need one more thing:
5) provide iterator support (begin(), end(), cbegin(), cend())
The current shared_array<> doesn't provide that - is there anything else that does?
Could you go and use an overloaded C++11 non-member std::begin( shared_array<> .. ) instead of the member .begin()? If so then you could try to write a simple generic non-member begin() for the shared_array<> (and ask if it can be added to boost)? This is a good example of why the C++11 non-member begin() syntax gives more flexibility.
On 10/14/2014 10:33 AM, Thijs (M.A.) van den Berg wrote:
Could you go and use an overloaded C++11 non-member std::begin( shared_array<> .. ) instead of the member .begin()?
If so then you could try to write a simple generic non-member begin() for the shared_array<> (and ask if it can be added to boost)?
I can look into that. I took a bit of time yesterday and wrote an template that extended the shared_array with member begin and end - it really didn't take much to do. When it gets some more review at work, I may submit what I've done to the list as a request for comment. Making end() work means adding another data member for the array length, and requiring that be set - I don't know if that would be deemed an acceptable burden on shared_array, and it may be that making an extension class available would be the right way to go.
participants (3)
-
David Hagood
-
david.hagood@gmail.com
-
Thijs (M.A.) van den Berg