summaryrefslogtreecommitdiff
path: root/AK/DistinctNumeric.h
AgeCommit message (Collapse)Author
2023-01-21AK: Add a type alias for DistinctNumeric's underlying typeTimothy Flynn
2023-01-07AK: Reimplement DistinctNumeric comparison operators using operator<=>Andrew Kaster
Unlike what the class comment says, it's actually valid to return int from this operator and treat it like a "normal" C-like compare method.
2023-01-06AK: Fix typo in -= operator of DistinctNumericAliaksandr Kalenik
2022-11-26AK: Make it possible to not `using` AK classes into the global namespaceAndreas Kling
This patch adds the `USING_AK_GLOBALLY` macro which is enabled by default, but can be overridden by build flags. This is a step towards integrating Jakt and AK types.
2022-11-11AK: Add optional explicit cast to underlying type to DistinctNumericSam Atkins
2022-11-11AK+Everywhere: Replace DistinctNumeric bool parameters with named onesSam Atkins
This means that rather than this: ``` AK_TYPEDEF_DISTINCT_NUMERIC_GENERAL(u64, true, true, false, false, false, true, FunctionAddress); ``` We now have this: ``` AK_TYPEDEF_DISTINCT_NUMERIC_GENERAL(u64, FunctionAddress, Arithmetic, Comparison, Increment); ``` Which is a lot more readable. :^) Co-authored-by: Ali Mohammad Pur <mpfard@serenityos.org>
2022-11-06Everywhere: Remove redundant inequality comparison operatorsDaniel Bertalan
C++20 can automatically synthesize `operator!=` from `operator==`, so there is no point in writing such functions by hand if all they do is call through to `operator==`. This fixes a compile error with compilers that implement P2468 (Clang 16 currently). This paper restores the C++17 behavior that if both `T::operator==(U)` and `T::operator!=(U)` exist, `U == T` won't be rewritten in reverse to call `T::operator==(U)`. Removing `!=` operators makes the rewriting possible again. See https://reviews.llvm.org/D134529#3853062
2022-07-22Everywhere: Prefix 'TYPEDEF_DISTINCT_ORDERED_ID' with 'AK_'Linus Groh
2022-07-22Everywhere: Prefix 'TYPEDEF_DISTINCT_NUMERIC_GENERAL' with 'AK_'Linus Groh
2022-04-01Everywhere: Run clang-formatIdan Horowitz
2022-03-27AK: Add non-const DistinctNumeric::value() getterLinus Groh
2022-01-07Everywhere: Fix many spelling errorsmjz19910
2021-11-17AK: Convert AK::Format formatting helpers to returning ErrorOr<void>Andreas Kling
This isn't a complete conversion to ErrorOr<void>, but a good chunk. The end goal here is to propagate buffer allocation failures to the caller, and allow the use of TRY() with formatting functions.
2021-10-21AK+Kernel: Format DistinctNumeric using the underlying type's formatterDaniel Bertalan
Forcing the formatting to go through `Formatter<FormatString>` is completely unnecessary, increases code size, performs a String allocation and prevents us from using the formatting options available on that type. This commit also removes explicit formatters from `BlockBasedFileSystem::BlockIndex` and `Kernel::InodeIndex`, as those are already covered by the blanket implementation for all `DistinctNumeric` types.
2021-09-16AK: Use default constructor/destructor instead of declaring an empty oneBrian Gianforcaro
Default implementations allow for more optimizations. See: https://pvs-studio.com/en/docs/warnings/v832/
2021-05-04AK: Make DistinctNumeric constexpr-capableAli Mohammad Pur
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-02-26Everywhere: Remove a bunch of redundant 'AK::' namespace prefixesLinus Groh
This is basically just for consistency, it's quite strange to see multiple AK container types next to each other, some with and some without the namespace prefix - we're 'using AK::Foo;' a lot and should leverage that. :^)
2021-02-12AK: Remove operators && and || from DistinctNumericAndreas Kling
These don't do short-circuit evaluation, and so I ran into some some very subtle side-effects when converting code to DistinctNumeric. In code like this: MyDistinctNumeric n; if (n && check_thing(n)) return; There would be no short-circuit evaluation if the return type of check_thing() was implicitly convertible to MyDistinctNumeric. Ran into this while making Ext2FS::GroupIndex a DistinctNumeric.
2021-02-12AK: Add formatter for DistinctNumericAndreas Kling
2021-02-12AK: Allow default-constructing DistinctNumericAndreas Kling
This makes it much more useful as a replacement type for integers. It's zeroed out by default.
2021-01-28AK: Provide traits for DistinctNumeric<T>AnotherTest
2020-11-12AK: Prefer using instead of typedefLenny Maiorani
Problem: - `typedef` is a keyword which comes from C and carries with it old syntax that is hard to read. - Creating type aliases with the `using` keyword allows for easier future maintenance because it supports template syntax. - There is inconsistent use of `typedef` vs `using`. Solution: - Use `clang-tidy`'s checker called `modernize-use-using` to update the syntax to use the newer syntax. - Remove unused functions to make `clang-tidy` happy. - This results in consistency within the codebase.
2020-08-22AK: Fix description of DistinctNumeric around operator boolBen Wiederhake
2020-08-10AK: Implement and test DistinctNumeric classBen Wiederhake
This template class allows for easy generation of incompatible numeric types. This is useful whenever code has to handle heterogenous data (like meters and seconds) but the underlying data types are compatible (like int and int). The motivation comes from the Kernel's inconsistent use of pid_t for process and thread IDs even though the ID spaces are incompatible, and translating forth/back is nontrivial. Other uses could be units (as described above), or incompatible index systems. A popular use in real life is image manipulation, when there are multiple coordinate systems.