How efficient is dispatching on a boost::variant ?
If it’s a switch statement, it should only take O(1) time, but as far as I know, template metaprogrammign can only generate if’s, which would put boost::variant dispatchs at a runtime overhead of O(n), where n = number of types in the variant.
Can anyone confirm/deny/enlighten me on this?
Thanks!
Looking at the source, it should be constant time. Boost uses Boost.PreProcessor to generate a switch-table, and keeps track of which index it should jump to (via the type being stored).