News for hackers. Stuff that matters.
Re:C++20 Concepts: The Definitive Guide by contravariant on Sunday August 22, 2021 @12:26PM (#28266808)
I guess this is somewhat besides the point but checking if something can be multiplied by -1 is not great as a definition of subtraction. You'll typically want to use the additive inverse directly.

I mean sure you can extend any commutative group into a module over the integers but you probably don't want to make this a hard requirement just to have subtraction.

Re:C++20 Concepts: The Definitive Guide by godelski on Sunday August 22, 2021 @03:52PM (#28268927)
Why would this be an issue? I'm under the impression that this is fine if we're operating with the standard addition operator and the standard field that everyone is used to working under. Isn't that the definition of the inverse? I understand that in different fields you have different operators but is that relevant here?
Re:C++20 Concepts: The Definitive Guide by MauranKilom on Sunday August 22, 2021 @05:21PM (#28269751)
Random example: In geometry code, you might distinguish between points and vectors, where point + vector = point, point - point = vector etc.

It can then also be convenient to have a special type/value Origin, which (while functionally identical to point(0, 0)) allows you to e.g. write vector = point - origin to clearly express your intent of turning a vector into a point.

-1 * origin is not meaningful, but point - origin is (while point + origin is not).

Re:C++20 Concepts: The Definitive Guide by godelski on Sunday August 22, 2021 @06:13PM (#28270178)
But in this case I don't think you're working on the standard field. I mean you're working in different coordinates. I do understand that the example only works in R1 space with standard addition, but that's kinda the point of my question. That the "error" isn't really an error unless you're being pretty pedantic.
Re:C++20 Concepts: The Definitive Guide by contravariant on Sunday August 22, 2021 @05:15PM (#28269693)
If you were working with the standard field then why would you need to bother defining the general concept of subtraction?

If you want to define the concept of subtraction then you probably don't want to assume you can multiply elements with an integer. Not that it can't be done but in general it will be a lot easier to define the additive inverse directly (if one exists).

Re:C++20 Concepts: The Definitive Guide by godelski on Sunday August 22, 2021 @06:17PM (#28270214)
I mean but under the example that the author is doing they are working with standard integers (integrals). So this appears to me to still be the standard addition and subtraction. And with standard R1 subtraction it is the same as inverse of addition.

I mean if we move into different coordinates and different fields, then yeah things change, but I don't see what the issue is with the example given here.

Re:C++20 Concepts: The Definitive Guide by ncmncm on Monday August 23, 2021 @03:25PM (#28280738)
This is correct. The expression tested in the concept definition should not be "-1*x", but "x-x".