Alex Rivera | Logout

Heterogeneous containers in C++

Asked 2011-10-18T09:15:22.177
28

I saw this nice graphic which classifies which STL container would suit based on different requirements of data such as:

-- Fixed Size Vs Variable size

-- Data of same tyme Vs different type

-- Sorted Vs unsorted data

-- Sequential Vs random access

http://plasmahh.projectiwear.org/cce_clean.svg

I notice in that image, that C++ STL there is no container which is

  1. Variable Size
  2. Heterogenous (data of different types).

Doesn't C++ have something for this?

PS - There can be many permutations made out the different properties of the containers and many others too might not be provided in STL.

Edit
Report

1 Answer

10

The basic principle in the standard library is that "containers" are homogeneous; the C++ standard doesn't consider things like std::pair or std::tuple to be containers. (I'd consider the graph misleading, since it does consider them as containers.) If you need a heterogeneous container, you'd have to use a container of boost::variant, or something along those lines.

answered 2011-10-18T09:22:29.103

Your Answer