Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is the ordering of std::type_index stable?

Tags:

c++

Can the ordering of std::type_index be relied on to be stable over

  • multiple invocations of the same executable file
  • multiple invocations of the different executable file with the number and names of classes not changed
  • even if some of these classes are defined in an unnamed namespace

I know that std::type_info does not guarantee such thing? Does std::type_index? Should one rather use std::type_info::name() for the ordering?

like image 601
Frank Puck Avatar asked Dec 28 '21 17:12

Frank Puck


Video Answer


1 Answers

type_info's comparison operators are based on type_index::before's behavior. And the standard specifically states that before provides no guarantees outside of the execution of a single program:

The names, encoding rule, and collating sequence for types are all unspecified and may differ between programs.

like image 119
Nicol Bolas Avatar answered Oct 22 '22 11:10

Nicol Bolas