Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which platforms don't use string comparison in type_info op==?

Here is a typical implementation of type_info::operator==:

#if _PLATFORM_SUPPORTS_UNIQUE_TYPEINFO
    bool operator==(const type_info& __rhs) const {
      return __mangled_name == __rhs.__mangled_name;
    }
#else
    bool operator==(const type_info& __rhs) const {
      return __mangled_name == __rhs.__mangled_name ||
             strcmp(__mangled_name, __rhs.__mangled_name) == 0;
    }
#endif

In libstdc++ it's controlled with __GXX_MERGED_TYPEINFO_NAMES,
in libc++ it's _LIBCPP_NONUNIQUE_RTTI_BIT,
MSVC always compares strings.

What are the platforms which don't compare strings?

like image 687
Abyx Avatar asked Apr 11 '18 11:04

Abyx


People also ask

What is the best way to compare strings in a project?

When you develop with .NET, follow these simple recommendations when you use strings: Use overloads that explicitly specify the string comparison rules for string operations. Use StringComparison.Ordinal or StringComparison.OrdinalIgnoreCase for comparisons as your safe default for culture-agnostic string matching.

What does the less than (<) comparison operator do in JavaScript?

The Less than (<) comparison operator checks if the left operand is less than its right operand. If yes then it returns true otherwise returns false.

How to compare strings in C #?

How to compare strings in C# 1 Default ordinal comparisons. ... 2 Case-insensitive ordinal comparisons. ... 3 Linguistic comparisons. ... 4 Comparisons using specific cultures. ... 5 Linguistic sorting and searching strings in arrays. ... 6 Ordinal sorting and searching in collections. ... 7 Reference equality and string interning. ...

What is the use of string compareTo?

CompareTo. The String.CompareTo method is primarily intended for use when ordering or sorting strings. You should not use the String.CompareTo method to test for equality (that is, to explicitly look for a return value of 0 with no regard for whether one string is less than or greater than the other).


1 Answers

In libstdc++ it's controlled with __GXX_MERGED_TYPEINFO_NAMES

In newer versions of gcc (since 23 Jul 2009) this macro is set to 0 by default. It always compares pointers first and if that fails they do the full string comparison. See here:

We used to do inline pointer comparison by default if weak symbols are available, but even with weak symbols sometimes names are not merged when objects are loaded with RTLD_LOCAL, so now we always use strcmp by default.

like image 52
Maxim Egorushkin Avatar answered Oct 10 '22 21:10

Maxim Egorushkin