Is is valid to construct std::set of pointer type?

前端 未结 1 1579
野趣味
野趣味 2021-01-19 03:29

I want to store some pointers into std::set, but the standard guide says it\'s invalid.

If two pointers p and q of the same type point to different ob

相关标签:
1条回答
  • 2021-01-19 03:34

    While it is true that built-in operator < only works for pointers into the same array, std::set and std::map don't use that operator - they use std::less. This, in turn, is guaranteed to impose a total order on all pointers:

    [comparisons]/2 For templates less, greater, less_equal, and greater_equal, the specializations for any pointer type yield a strict total order that is consistent among those specializations and is also consistent with the partial order imposed by the built-in operators <, >, <=, >=.

    0 讨论(0)
提交回复
热议问题