
I just took a look at boost::any and boost::variant (I haven't really worked with these, so unfamiliar) and it looks like this idea definitely do-able. I think that the restriction is that the container elements must implement a type() method so that when requesting one specific data type, we do not return another type which has been cast into the type requested. I think this is a more generally applicable method than designing one container which does this. I like the vector_tuple idea as well and think there is definite merit to storing data of the same type together in order to improve efficiency. In that scenario, I think there is no getting around designing a container/adapter specifically for that (I could be wrong). On Tue, May 5, 2015 at 4:23 PM, Boris Rasin <boris@pointx.org> wrote:
On 5/6/2015 1:08 AM, James Armstrong wrote:
Do you mean something that would work along the lines of...
std::vector<boost::any> my_vec; // fill my_vec with various data types
//iterate through doubles for (auto itr = itr_begin<double>(my_vec); itr != itr_end<double>(my_vec); ++itr) { // ... }
//iterate through strings for (auto itr = itr_begin<std::string>(my_vec); itr != itr_end<std::string>(my_vec); ++itr) { // ... }
where itr_begin and itr_end generate iterators for the templated type over any container of type erased objects. I didn't quite get what you were suggesting at first, but yeah I think I agree that would be more useful.
Yes. And this would work with std::vector<boost::any> and std::list<boost::variant> alike.
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
-- James Armstrong