rttrorg / rttr

C++ Reflection Library
https://www.rttr.org
MIT License
3.12k stars 430 forks source link

register std::vector<int>, std::set<int> at the same time, the last registration survives, why? #307

Closed lc-Arvin closed 3 years ago

lc-Arvin commented 3 years ago

Hello,

I am wondering if I can register containers with rttr and I found it works well. But the following case happens:

‘’‘

rttr::registration::class_<std::vector<int>>("std::vector<int>")
                    .constructor<>()(rttr::policy::ctor::as_object)
                    ;
rttr::registration::class_<std::set<int>>("std::set<int>")
                    .constructor<>()(rttr::policy::ctor::as_object)
                    ;
rttr::registration::class_<std::map<int, int>>("std::map<int, int>")
                    .constructor<>()(rttr::policy::ctor::as_object)
                    ;
std::cout << "\ntype std::vector<int> : "   << type::get_by_name("std::vector<int>").is_valid()
              << "\ntype std::set<int> : "      << type::get_by_name("std::set<int>").is_valid()
              << "\ntype std::map<int, int> : " << type::get_by_name("std::map<int, int>").is_valid()

’‘’

the output shows the last registration of the type std::map<int, int> survives.

'''

type std::vector : 0 type std::set : 0 type std::map<int, int> : 1

'''

If I register only std::vector or std::set or std::map<int, int>, either type will be valid then. I tried to understand why but couldn't get the root cause yet. Could you please help? Thanks! @acki-m

lc-Arvin commented 3 years ago

by tracking the registration process, when registering std::set after std::vector, the name of std::vector will be changed by function rttr::type_register_private::derive_template_instance_name.

close the issue for now.