Il 14/06/2016 02:07, Gavin Lambert ha scritto:
On 14/06/2016 10:31, Giuseppe Campana wrote:
The problem I see with both a tuple_vector and a vector of boost::variant's is that the types that can be added to the containers are part of the declaration of the container, so you have to know them in advance. When this is possible IMO you approach is good. Density is addressing the case in which the declaration of the container can't depend on the type of elements. Think to the dense_function_queue. An element of this container may be the result of an std::bind, or a lambda, which are unnamed types.
Sounds like you should have a comparison between this and std::vector/queue/whateverboost::any.
Good idea. I've added two simple comparative tests with boost::any (http://peggysansonetti.it/tech/density/html/any_bench.html). In the first test, in contrast to my expectations, std::queue is performing worse than std::vector. Thank you for your suggestion, Gavin. By the way, what do you, boost people, think about the names of the containers of density? The same class template (for example dense_queue) can be used for polymorphic types (the usual Widget) and for any type (using void as base element type). There is no partial specialization, the same template works in both cases. The rationale is the same of the void pointer. Anyway C++17 already uses the name 'any' for a type-erased single value. So another option for density would be splitting the containers in two: any_list, any_queue, etc., for fully type-erased containers, and polymorphic_list, polymorphic_queue, etc. for 'partially' type-erased containers. Anyway I'm not sure about this...