Re:Writing your own C++ standard library from scratch
by logicchains on Tuesday March 25, 2025 @05:41AM
(#43469466)
At least you have the chance to implement your own std::partial_ordering if necessary; in most languages those kind of features would be built into the compiler.
[ Parent
| on HN ]
Re:Writing your own C++ standard library from scratch
by eru on Tuesday March 25, 2025 @07:06AM
(#43469868)
Haskell solves this nicely: your own operators just shadow the built-in operators. (And you can opt to not import the built-in operators, and only use your own. Just like you can opt not to import printf in C.)
Re:Writing your own C++ standard library from scratch
by dataangel on Tuesday March 25, 2025 @10:15AM
(#43471631)
that's not the issue, the problem is the operator is required by the language to return a type from the stdlib, so you have to pull in the stdlib to get that type
Re:Writing your own C++ standard library from scratch
by eru on Tuesday March 25, 2025 @09:11PM
(#43477821)
In Haskell, when you define your own operators (including those that have the same name as those already defined in the standard library), you can specify your own types.
There's basically no operators defined 'by the language' in Haskell, they are all defined in the standard library.
(Of course, the standard library behaves as-if it defines eg (+) on integers in terms of some intrinsic introduced by the compiler.)