代码之家  ›  专栏  ›  技术社区  ›  PiotrK

C++中的整数到模板类型集合

  •  2
  • PiotrK  · 技术社区  · 8 年前

    type

    std::map<uint32_t, std::type_index> type;
    

    std::type_index 有用性很小。我需要能够按该类型进行强制转换,并将其用作 std::is_convertible

    my_collection.add<1234, std::string>();
    my_collection.get<1234>()::type // type is std::string
    

    或者其他我可以在运行时使用的足够接近的东西:)

    1 回复  |  直到 8 年前
        1
  •  2
  •   Yakk - Adam Nevraumont    8 年前

    std::variant boost::variant

    如果您支持的类型上的操作列表可以有限地集中枚举, std::any 或 boost::any Here is an overly generic system to type erase nearly any single-dispatch operation .

    或 boots::any

    你可以把上面的结合起来。