2020-08-07 22:54:49 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Ben Wiederhake <BenWiederhake.GitHub@gmx.de>
|
2021-02-12 11:31:09 +00:00
|
|
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
|
2020-08-07 22:54:49 +00:00
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-08-07 22:54:49 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-02-12 11:31:09 +00:00
|
|
|
#include <AK/Format.h>
|
2021-01-28 15:42:48 +00:00
|
|
|
#include <AK/Traits.h>
|
2020-08-07 22:54:49 +00:00
|
|
|
#include <AK/Types.h>
|
|
|
|
|
|
|
|
namespace AK {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This implements a "distinct" numeric type that is intentionally incompatible
|
|
|
|
* to other incantations. The intention is that each "distinct" type that you
|
|
|
|
* want simply gets different values for `fn_length` and `line`. The macros
|
|
|
|
* `TYPEDEF_DISTINCT_NUMERIC_*()` at the bottom of `DistinctNumeric.h`.
|
|
|
|
*
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
* The tags in `DistinctNumericFeature` simply split up the space of operators into 6 simple categories:
|
2020-08-07 22:54:49 +00:00
|
|
|
* - No matter the values of these, `DistinctNumeric` always implements `==` and `!=`.
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
* - If `Arithmetic` is present, then `a+b`, `a-b`, `+a`, `-a`, `a*b`, `a/b`, `a%b`, and the respective `a_=b` versions are implemented.
|
|
|
|
* - If `CastToBool` is present, then `!a`, `a&&b`, and `a||b` are implemented (but not `operator bool()`, because of overzealous integer promotion rules).
|
2023-01-02 07:31:58 +00:00
|
|
|
* - If `Comparison` is present, then `a>b`, `a<b`, `a>=b`, and `a<=b` are implemented via operator<=>
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
* - If `Flags` is present, then `~a`, `a&b`, `a|b`, `a^b`, `a&=b`, `a|=b`, and `a^=b` are implemented.
|
|
|
|
* - If `Increment` is present, then `++a`, `a++`, `--a`, and `a--` are implemented.
|
|
|
|
* - If `Shift` is present, then `a<<b`, `a>>b`, `a<<=b`, `a>>=b` are implemented.
|
2020-08-07 22:54:49 +00:00
|
|
|
* The semantics are always those of the underlying basic type `T`.
|
|
|
|
*
|
|
|
|
* These can be combined arbitrarily. Want a numeric type that supports `++a`
|
|
|
|
* and `a >> b` but not `a > b`? Sure thing, just set
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
* `Increment, Comparison, Shift` and you're done!
|
2020-08-07 22:54:49 +00:00
|
|
|
* Furthermore, some of these overloads make more sense with specific types, like `a&&b` which should be able to operate
|
|
|
|
*
|
|
|
|
* I intentionally decided against overloading `&a` because these shall remain
|
|
|
|
* numeric types.
|
|
|
|
*
|
|
|
|
* The are many operators that do not work on `int`, so I left them out:
|
|
|
|
* `a[b]`, `*a`, `a->b`, `a.b`, `a->*b`, `a.*b`.
|
|
|
|
*
|
|
|
|
* There are many more operators that do not make sense for numerical types,
|
|
|
|
* or cannot be overloaded in the first place. Naturally, they are not implemented.
|
|
|
|
*/
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
|
|
|
|
namespace DistinctNumericFeature {
|
|
|
|
enum Arithmetic {};
|
|
|
|
enum CastToBool {};
|
2022-11-10 16:20:07 +00:00
|
|
|
enum CastToUnderlying {};
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
enum Comparison {};
|
|
|
|
enum Flags {};
|
|
|
|
enum Increment {};
|
|
|
|
enum Shift {};
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T, typename X, typename... Opts>
|
2020-08-07 22:54:49 +00:00
|
|
|
class DistinctNumeric {
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
using Self = DistinctNumeric<T, X, Opts...>;
|
|
|
|
|
|
|
|
struct Option {
|
|
|
|
template<typename K, typename... Os>
|
|
|
|
consteval Option(K option, Os... other_options)
|
|
|
|
: Option(other_options...)
|
|
|
|
{
|
|
|
|
set(option);
|
|
|
|
}
|
|
|
|
|
|
|
|
consteval Option() { }
|
|
|
|
|
|
|
|
constexpr void set(DistinctNumericFeature::Arithmetic const&) { arithmetic = true; }
|
|
|
|
constexpr void set(DistinctNumericFeature::CastToBool const&) { cast_to_bool = true; }
|
2022-11-10 16:20:07 +00:00
|
|
|
constexpr void set(DistinctNumericFeature::CastToUnderlying const&) { cast_to_underlying = true; }
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
constexpr void set(DistinctNumericFeature::Comparison const&) { comparisons = true; }
|
|
|
|
constexpr void set(DistinctNumericFeature::Flags const&) { flags = true; }
|
|
|
|
constexpr void set(DistinctNumericFeature::Increment const&) { increment = true; }
|
|
|
|
constexpr void set(DistinctNumericFeature::Shift const&) { shift = true; }
|
|
|
|
|
|
|
|
bool arithmetic { false };
|
|
|
|
bool cast_to_bool { false };
|
2022-11-10 16:20:07 +00:00
|
|
|
bool cast_to_underlying { false };
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
bool comparisons { false };
|
|
|
|
bool flags { false };
|
|
|
|
bool increment { false };
|
|
|
|
bool shift { false };
|
|
|
|
};
|
|
|
|
|
|
|
|
constexpr static Option options { Opts()... };
|
2020-08-07 22:54:49 +00:00
|
|
|
|
|
|
|
public:
|
2023-01-20 20:32:34 +00:00
|
|
|
using Type = T;
|
|
|
|
|
2021-09-16 06:20:31 +00:00
|
|
|
constexpr DistinctNumeric() = default;
|
2021-02-12 10:58:46 +00:00
|
|
|
|
2021-04-25 17:57:54 +00:00
|
|
|
constexpr DistinctNumeric(T value)
|
2020-08-07 22:54:49 +00:00
|
|
|
: m_value { value }
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
constexpr T const& value() const { return m_value; }
|
2022-03-27 11:47:57 +00:00
|
|
|
constexpr T& value() { return m_value; }
|
2020-08-07 22:54:49 +00:00
|
|
|
|
|
|
|
// Always implemented: identity.
|
2022-04-01 17:58:27 +00:00
|
|
|
constexpr bool operator==(Self const& other) const
|
2020-08-07 22:54:49 +00:00
|
|
|
{
|
|
|
|
return this->m_value == other.m_value;
|
|
|
|
}
|
|
|
|
|
2022-11-10 16:20:07 +00:00
|
|
|
// Only implemented when `CastToUnderlying` is true:
|
|
|
|
constexpr explicit operator T() const
|
|
|
|
{
|
|
|
|
static_assert(options.cast_to_underlying, "Cast to underlying type is only available for DistinctNumeric types with 'CastToUnderlying'.");
|
|
|
|
return value();
|
|
|
|
}
|
|
|
|
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
// Only implemented when `Increment` is true:
|
2021-04-25 17:57:54 +00:00
|
|
|
constexpr Self& operator++()
|
2020-08-07 22:54:49 +00:00
|
|
|
{
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
static_assert(options.increment, "'++a' is only available for DistinctNumeric types with 'Increment'.");
|
2020-08-07 22:54:49 +00:00
|
|
|
this->m_value += 1;
|
|
|
|
return *this;
|
|
|
|
}
|
2021-04-25 17:57:54 +00:00
|
|
|
constexpr Self operator++(int)
|
2020-08-07 22:54:49 +00:00
|
|
|
{
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
static_assert(options.increment, "'a++' is only available for DistinctNumeric types with 'Increment'.");
|
2020-08-07 22:54:49 +00:00
|
|
|
Self ret = this->m_value;
|
|
|
|
this->m_value += 1;
|
|
|
|
return ret;
|
|
|
|
}
|
2021-04-25 17:57:54 +00:00
|
|
|
constexpr Self& operator--()
|
2020-08-07 22:54:49 +00:00
|
|
|
{
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
static_assert(options.increment, "'--a' is only available for DistinctNumeric types with 'Increment'.");
|
2020-08-07 22:54:49 +00:00
|
|
|
this->m_value -= 1;
|
|
|
|
return *this;
|
|
|
|
}
|
2021-04-25 17:57:54 +00:00
|
|
|
constexpr Self operator--(int)
|
2020-08-07 22:54:49 +00:00
|
|
|
{
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
static_assert(options.increment, "'a--' is only available for DistinctNumeric types with 'Increment'.");
|
2020-08-07 22:54:49 +00:00
|
|
|
Self ret = this->m_value;
|
|
|
|
this->m_value -= 1;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
// Only implemented when `Comparison` is true:
|
2023-01-02 07:31:58 +00:00
|
|
|
constexpr int operator<=>(Self const& other) const
|
2020-08-07 22:54:49 +00:00
|
|
|
{
|
2023-01-02 07:31:58 +00:00
|
|
|
static_assert(options.comparisons, "'a<=>b' is only available for DistinctNumeric types with 'Comparison'.");
|
|
|
|
return this->m_value > other.m_value ? 1 : this->m_value < other.m_value ? -1
|
|
|
|
: 0;
|
2020-08-07 22:54:49 +00:00
|
|
|
}
|
|
|
|
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
// Only implemented when `CastToBool` is true:
|
2021-04-25 17:57:54 +00:00
|
|
|
constexpr bool operator!() const
|
2020-08-07 22:54:49 +00:00
|
|
|
{
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
static_assert(options.cast_to_bool, "'!a' is only available for DistinctNumeric types with 'CastToBool'.");
|
2020-08-07 22:54:49 +00:00
|
|
|
return !this->m_value;
|
|
|
|
}
|
|
|
|
// Intentionally don't define `operator bool() const` here. C++ is a bit
|
2022-01-06 14:07:15 +00:00
|
|
|
// overzealous, and whenever there would be a type error, C++ instead tries
|
2020-08-07 22:54:49 +00:00
|
|
|
// to convert to a common int-ish type first. `bool` is int-ish, so
|
|
|
|
// `operator bool() const` would defy the entire point of this class.
|
|
|
|
|
|
|
|
// Only implemented when `Flags` is true:
|
2021-04-25 17:57:54 +00:00
|
|
|
constexpr Self operator~() const
|
2020-08-07 22:54:49 +00:00
|
|
|
{
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
static_assert(options.flags, "'~a' is only available for DistinctNumeric types with 'Flags'.");
|
2020-08-07 22:54:49 +00:00
|
|
|
return ~this->m_value;
|
|
|
|
}
|
2022-04-01 17:58:27 +00:00
|
|
|
constexpr Self operator&(Self const& other) const
|
2020-08-07 22:54:49 +00:00
|
|
|
{
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
static_assert(options.flags, "'a&b' is only available for DistinctNumeric types with 'Flags'.");
|
2020-08-07 22:54:49 +00:00
|
|
|
return this->m_value & other.m_value;
|
|
|
|
}
|
2022-04-01 17:58:27 +00:00
|
|
|
constexpr Self operator|(Self const& other) const
|
2020-08-07 22:54:49 +00:00
|
|
|
{
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
static_assert(options.flags, "'a|b' is only available for DistinctNumeric types with 'Flags'.");
|
2020-08-07 22:54:49 +00:00
|
|
|
return this->m_value | other.m_value;
|
|
|
|
}
|
2022-04-01 17:58:27 +00:00
|
|
|
constexpr Self operator^(Self const& other) const
|
2020-08-07 22:54:49 +00:00
|
|
|
{
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
static_assert(options.flags, "'a^b' is only available for DistinctNumeric types with 'Flags'.");
|
2020-08-07 22:54:49 +00:00
|
|
|
return this->m_value ^ other.m_value;
|
|
|
|
}
|
2022-04-01 17:58:27 +00:00
|
|
|
constexpr Self& operator&=(Self const& other)
|
2020-08-07 22:54:49 +00:00
|
|
|
{
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
static_assert(options.flags, "'a&=b' is only available for DistinctNumeric types with 'Flags'.");
|
2020-08-07 22:54:49 +00:00
|
|
|
this->m_value &= other.m_value;
|
|
|
|
return *this;
|
|
|
|
}
|
2022-04-01 17:58:27 +00:00
|
|
|
constexpr Self& operator|=(Self const& other)
|
2020-08-07 22:54:49 +00:00
|
|
|
{
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
static_assert(options.flags, "'a|=b' is only available for DistinctNumeric types with 'Flags'.");
|
2020-08-07 22:54:49 +00:00
|
|
|
this->m_value |= other.m_value;
|
|
|
|
return *this;
|
|
|
|
}
|
2022-04-01 17:58:27 +00:00
|
|
|
constexpr Self& operator^=(Self const& other)
|
2020-08-07 22:54:49 +00:00
|
|
|
{
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
static_assert(options.flags, "'a^=b' is only available for DistinctNumeric types with 'Flags'.");
|
2020-08-07 22:54:49 +00:00
|
|
|
this->m_value ^= other.m_value;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only implemented when `Shift` is true:
|
|
|
|
// TODO: Should this take `int` instead?
|
2022-04-01 17:58:27 +00:00
|
|
|
constexpr Self operator<<(Self const& other) const
|
2020-08-07 22:54:49 +00:00
|
|
|
{
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
static_assert(options.shift, "'a<<b' is only available for DistinctNumeric types with 'Shift'.");
|
2020-08-07 22:54:49 +00:00
|
|
|
return this->m_value << other.m_value;
|
|
|
|
}
|
2022-04-01 17:58:27 +00:00
|
|
|
constexpr Self operator>>(Self const& other) const
|
2020-08-07 22:54:49 +00:00
|
|
|
{
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
static_assert(options.shift, "'a>>b' is only available for DistinctNumeric types with 'Shift'.");
|
2020-08-07 22:54:49 +00:00
|
|
|
return this->m_value >> other.m_value;
|
|
|
|
}
|
2022-04-01 17:58:27 +00:00
|
|
|
constexpr Self& operator<<=(Self const& other)
|
2020-08-07 22:54:49 +00:00
|
|
|
{
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
static_assert(options.shift, "'a<<=b' is only available for DistinctNumeric types with 'Shift'.");
|
2020-08-07 22:54:49 +00:00
|
|
|
this->m_value <<= other.m_value;
|
|
|
|
return *this;
|
|
|
|
}
|
2022-04-01 17:58:27 +00:00
|
|
|
constexpr Self& operator>>=(Self const& other)
|
2020-08-07 22:54:49 +00:00
|
|
|
{
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
static_assert(options.shift, "'a>>=b' is only available for DistinctNumeric types with 'Shift'.");
|
2020-08-07 22:54:49 +00:00
|
|
|
this->m_value >>= other.m_value;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
// Only implemented when `Arithmetic` is true:
|
2022-04-01 17:58:27 +00:00
|
|
|
constexpr Self operator+(Self const& other) const
|
2020-08-07 22:54:49 +00:00
|
|
|
{
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
static_assert(options.arithmetic, "'a+b' is only available for DistinctNumeric types with 'Arithmetic'.");
|
2020-08-07 22:54:49 +00:00
|
|
|
return this->m_value + other.m_value;
|
|
|
|
}
|
2022-04-01 17:58:27 +00:00
|
|
|
constexpr Self operator-(Self const& other) const
|
2020-08-07 22:54:49 +00:00
|
|
|
{
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
static_assert(options.arithmetic, "'a-b' is only available for DistinctNumeric types with 'Arithmetic'.");
|
2020-08-07 22:54:49 +00:00
|
|
|
return this->m_value - other.m_value;
|
|
|
|
}
|
2021-04-25 17:57:54 +00:00
|
|
|
constexpr Self operator+() const
|
2020-08-07 22:54:49 +00:00
|
|
|
{
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
static_assert(options.arithmetic, "'+a' is only available for DistinctNumeric types with 'Arithmetic'.");
|
2020-08-07 22:54:49 +00:00
|
|
|
return +this->m_value;
|
|
|
|
}
|
2021-04-25 17:57:54 +00:00
|
|
|
constexpr Self operator-() const
|
2020-08-07 22:54:49 +00:00
|
|
|
{
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
static_assert(options.arithmetic, "'-a' is only available for DistinctNumeric types with 'Arithmetic'.");
|
2020-08-07 22:54:49 +00:00
|
|
|
return -this->m_value;
|
|
|
|
}
|
2022-04-01 17:58:27 +00:00
|
|
|
constexpr Self operator*(Self const& other) const
|
2020-08-07 22:54:49 +00:00
|
|
|
{
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
static_assert(options.arithmetic, "'a*b' is only available for DistinctNumeric types with 'Arithmetic'.");
|
2020-08-07 22:54:49 +00:00
|
|
|
return this->m_value * other.m_value;
|
|
|
|
}
|
2022-04-01 17:58:27 +00:00
|
|
|
constexpr Self operator/(Self const& other) const
|
2020-08-07 22:54:49 +00:00
|
|
|
{
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
static_assert(options.arithmetic, "'a/b' is only available for DistinctNumeric types with 'Arithmetic'.");
|
2020-08-07 22:54:49 +00:00
|
|
|
return this->m_value / other.m_value;
|
|
|
|
}
|
2022-04-01 17:58:27 +00:00
|
|
|
constexpr Self operator%(Self const& other) const
|
2020-08-07 22:54:49 +00:00
|
|
|
{
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
static_assert(options.arithmetic, "'a%b' is only available for DistinctNumeric types with 'Arithmetic'.");
|
2020-08-07 22:54:49 +00:00
|
|
|
return this->m_value % other.m_value;
|
|
|
|
}
|
2022-04-01 17:58:27 +00:00
|
|
|
constexpr Self& operator+=(Self const& other)
|
2020-08-07 22:54:49 +00:00
|
|
|
{
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
static_assert(options.arithmetic, "'a+=b' is only available for DistinctNumeric types with 'Arithmetic'.");
|
2020-08-07 22:54:49 +00:00
|
|
|
this->m_value += other.m_value;
|
|
|
|
return *this;
|
|
|
|
}
|
2022-04-01 17:58:27 +00:00
|
|
|
constexpr Self& operator-=(Self const& other)
|
2020-08-07 22:54:49 +00:00
|
|
|
{
|
2023-01-05 18:14:23 +00:00
|
|
|
static_assert(options.arithmetic, "'a-=b' is only available for DistinctNumeric types with 'Arithmetic'.");
|
|
|
|
this->m_value -= other.m_value;
|
2020-08-07 22:54:49 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2022-04-01 17:58:27 +00:00
|
|
|
constexpr Self& operator*=(Self const& other)
|
2020-08-07 22:54:49 +00:00
|
|
|
{
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
static_assert(options.arithmetic, "'a*=b' is only available for DistinctNumeric types with 'Arithmetic'.");
|
2020-08-07 22:54:49 +00:00
|
|
|
this->m_value *= other.m_value;
|
|
|
|
return *this;
|
|
|
|
}
|
2022-04-01 17:58:27 +00:00
|
|
|
constexpr Self& operator/=(Self const& other)
|
2020-08-07 22:54:49 +00:00
|
|
|
{
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
static_assert(options.arithmetic, "'a/=b' is only available for DistinctNumeric types with 'Arithmetic'.");
|
2020-08-07 22:54:49 +00:00
|
|
|
this->m_value /= other.m_value;
|
|
|
|
return *this;
|
|
|
|
}
|
2022-04-01 17:58:27 +00:00
|
|
|
constexpr Self& operator%=(Self const& other)
|
2020-08-07 22:54:49 +00:00
|
|
|
{
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
static_assert(options.arithmetic, "'a%=b' is only available for DistinctNumeric types with 'Arithmetic'.");
|
2020-08-07 22:54:49 +00:00
|
|
|
this->m_value %= other.m_value;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2021-02-12 10:58:46 +00:00
|
|
|
T m_value {};
|
2020-08-07 22:54:49 +00:00
|
|
|
};
|
|
|
|
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
template<typename T, typename X, typename... Opts>
|
|
|
|
struct Formatter<DistinctNumeric<T, X, Opts...>> : Formatter<T> {
|
|
|
|
ErrorOr<void> format(FormatBuilder& builder, DistinctNumeric<T, X, Opts...> value)
|
2021-02-12 11:31:09 +00:00
|
|
|
{
|
2021-09-04 19:28:45 +00:00
|
|
|
return Formatter<T>::format(builder, value.value());
|
2021-02-12 11:31:09 +00:00
|
|
|
}
|
|
|
|
};
|
2020-08-07 22:54:49 +00:00
|
|
|
}
|
|
|
|
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
#define AK_TYPEDEF_DISTINCT_NUMERIC_GENERAL(T, NAME, ...) \
|
|
|
|
struct NAME##_decl { \
|
|
|
|
using Arithmetic [[maybe_unused]] = AK::DistinctNumericFeature::Arithmetic; \
|
|
|
|
using CastToBool [[maybe_unused]] = AK::DistinctNumericFeature::CastToBool; \
|
2022-11-10 16:20:07 +00:00
|
|
|
using CastToUnderlying [[maybe_unused]] = AK::DistinctNumericFeature::CastToUnderlying; \
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
using Comparison [[maybe_unused]] = AK::DistinctNumericFeature::Comparison; \
|
|
|
|
using Flags [[maybe_unused]] = AK::DistinctNumericFeature::Flags; \
|
|
|
|
using Increment [[maybe_unused]] = AK::DistinctNumericFeature::Increment; \
|
|
|
|
using Shift [[maybe_unused]] = AK::DistinctNumericFeature::Shift; \
|
|
|
|
using NAME [[maybe_unused]] = DistinctNumeric<T, struct __##NAME##_tag, ##__VA_ARGS__>; \
|
|
|
|
}; \
|
|
|
|
using NAME = typename NAME##_decl::NAME;
|
|
|
|
|
|
|
|
#define AK_TYPEDEF_DISTINCT_ORDERED_ID(T, NAME) AK_TYPEDEF_DISTINCT_NUMERIC_GENERAL(T, NAME, Comparison, CastToBool)
|
2020-11-11 22:21:01 +00:00
|
|
|
// TODO: Further type aliases?
|
2020-08-07 22:54:49 +00:00
|
|
|
|
2023-09-11 13:07:03 +00:00
|
|
|
#define AK_MAKE_DISTINCT_NUMERIC_COMPARABLE_TO_ENUM(DN, E) \
|
|
|
|
constexpr bool operator==(DN n, E e) { return n.value() == to_underlying(e); }
|
|
|
|
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
template<typename T, typename X, typename... Opts>
|
|
|
|
struct Traits<AK::DistinctNumeric<T, X, Opts...>> : public GenericTraits<AK::DistinctNumeric<T, X, Opts...>> {
|
2021-01-28 15:42:48 +00:00
|
|
|
static constexpr bool is_trivial() { return true; }
|
AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
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-10 15:43:23 +00:00
|
|
|
static constexpr auto hash(DistinctNumeric<T, X, Opts...> const& d) { return Traits<T>::hash(d.value()); }
|
2021-01-28 15:42:48 +00:00
|
|
|
};
|
|
|
|
|
2022-11-26 11:18:30 +00:00
|
|
|
#if USING_AK_GLOBALLY
|
2020-08-07 22:54:49 +00:00
|
|
|
using AK::DistinctNumeric;
|
2022-11-26 11:18:30 +00:00
|
|
|
#endif
|