Boost logo

Boost :

Subject: Re: [boost] tuple_vector (was poly_collection)
From: Thijs van den Berg (thijs_at_[hidden])
Date: 2014-08-24 18:19:28


>
>>
>> The usage should be as close to std::vector as possible, so e.g.:
>>
>> |tuple_vector<std::tuple<T1, T2, T3, ...>> v;
>> v.resize(count);
>>
>> for (int i = 0; i < count; ++i)
>> {
>> T1 t = std::get<0>(v[i]);
>> std::get<0>(v[i]) = ...;
>> }|
>>
>>
>> A thing worth noticing is that the tuple_vector's reference type is a
>> tuple of references:
>>
>> std::tuple<T1&, T2&>
>
> Could also be any proxy type, that's more flexible.
> The important aspect is that tuple_vector's reference cannot be value_type&.
>

I’ve been looking at heterogenous containers without type erasure using tuple_vectors. My solution was to define an “invoke” function that allowed you to manipulate all (types) of elements in the container.

In this example I have a set of shapes in the tuple_vector like circle, rectangle… and a set of operations like move, rotate that I invoke on all elements.

Here is the C++14 code snippet:
http://pastebin.com/s7dBfWDX


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk