S
S
SaveliTomak2016-04-07 19:48:45
C++ / C#
SaveliTomak, 2016-04-07 19:48:45

How to understand if a data type can be compared with each other?

I implement a dynamic array, hands reached sorting. How to understand whether it is generally possible to compare the data type that the user specified in the class template. It is clear that int and char are compared with each other, but what if the user passed some specific data type (for example, his own class)? How then to understand that this data type can be compared? Maybe he implements some kind of basic interface in C ++?
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Bogachev, 2016-04-07
@sfi0zy

If the user wants to use their class with your array, they will have to use the operator overloads (==, <, >) that you probably use when sorting. The fact is that they are not automatically determined for user classes (which is logical - the compiler cannot guess how to compare, for example, boxes - by volume or by weight).

M
Maxim Moseychuk, 2016-04-08
@fshp

SFINAE
www.boost.org/doc/libs/1_61_0_b1/libs/type_traits/...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question