I need a general way to create unique compile-time identifiers for any custom C ++ types.
eg:
unique_id<my_type>::value == 0
unique_id<other_type>::value == 1
I managed to implement something like this using preprocessor metaprogramming, the problem is that serialization is incompatible. For example, if you first unique_idcreate an instance template using other_type, then any serialization in previous versions of my program will be invalidated.
I searched for solutions to this problem and found several ways to implement this with incompatible serialization if the unique values ββare compile time constants. If RTTI or similar methods are used, such as boost::sp_typeinfo, then the unique values ββare obviously not compile-time constants and additional overhead is present. A special solution to this problem would be to create a unique_id instance in a separate header in the correct order, but this will cause an additional service code and template, which is no different from use enum unique_id{my_type, other_type};.
A good solution to this problem would be to use custom literals, unfortunately, as far as I know, no compiler supports them at the moment. The syntax will be 'my_type'_id; 'other_type'_id;using udl.
, - , ++ (++ 03/++ 0x), , MSVC GNU-g++, , , .
, mpl::set , mpl::vector , , -/ , .