Boost logo

Boost Users :

Subject: Re: [Boost-users] Map runtime value to type
From: Michael (mwpowellhtx_at_[hidden])
Date: 2015-07-31 06:14:15


On July 31, 2015 6:01:04 AM EDT, dariomt_at_[hidden] wrote:
>Hi all,
>
>Say I have a compile-time map of <value,type> pairs, and I need to
>access
>the correct element given a value at runtime and do something with that
>type. That something would be the same for any of the mapped types
>(e.g.
>calling an overloaded function that would then do the right thing
>depending
>on the type).
>
>The value would typically be an enum.
>
>Is there anything in the Boost libraries to help with this?
>
>If I used C++11, would there be a simple solution to this?

Not really a boost question, perhaps.

First, I'm not sure why anyone wouldn't leverage at least C++11+. Especially considering compiler advancements in recent history. Optimization technology being what it is and all.

That said, if it was me, I might have a look at a std::function (or boost::function) "type factory" that knew how to interface with an instance repository.

Could be a functor instance, as well, for that matter.

>Regards

Cheers.

>PS: I cannot use Boost.Variant

Why not?

>
>------------------------------------------------------------------------
>
>_______________________________________________
>Boost-users mailing list
>Boost-users_at_[hidden]
>http://lists.boost.org/mailman/listinfo.cgi/boost-users

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net