News for hackers. Stuff that matters.
Re:Show HN: Floating point arithmetic types in C++ for any s... by seg_fault on Monday October 21, 2024 @04:48PM (#41908384)
I don't get what you mean. I thought they specify how the type can be used?
Re:Show HN: Floating point arithmetic types in C++ for any s... by badmintonbaseba on Monday October 21, 2024 @05:25PM (#41908663)
The cppreference page says:

> If the program adds specializations for std::is_fundamental or std::is_fundamental_v, the behavior is undefined.

This is an oversimplification. The actual rule is https://eel.is/c++draft/library#namespace.std-2 .

> the specialization meets the standard library requirements for the original template.

For is_fundamental<YourClassType> it means that is_fundamental<YourClassType>::value must be false, as YourClassType is not a fundamental type, as defined in https://eel.is/c++draft/basic.fundamental#17 .

Some traits are just not designed to be customization points.

Re:Show HN: Floating point arithmetic types in C++ for any s... by secondcoming on Monday October 21, 2024 @05:19PM (#41908617)
Technically, you're not supposed to add your own specialisations to the `std` namespace
Re:Show HN: Floating point arithmetic types in C++ for any s... by pmalynin on Monday October 21, 2024 @05:45PM (#41908849)
In general this isn’t true (i guess it is in this specific context). For example I believe it’s totally expected to specialize std hash
Re:Show HN: Floating point arithmetic types in C++ for any s... by tyleo on Monday October 21, 2024 @07:30PM (#41909632)
I’ve also done this with hash… though given the footguns scattered about, I wouldn’t be surprised if it broke the spec.
Re:Show HN: Floating point arithmetic types in C++ for any s... by Conscat on Tuesday October 22, 2024 @12:36AM (#41911240)
That is a completely intended way to use std::hash, along with a few other functions like std::tuple_size and std::tuple_element.