Commit Graph

19 Commits

Author SHA1 Message Date
Ali Mohammad Pur
15f95220ae AK+Everywhere: Delete Variant's default constructor
This was exposed to the user by mistake, and even accumulated a bunch of
users that didn't blow up out of sheer luck.
2021-08-13 17:31:39 +04:30
Ali Mohammad Pur
dcf795085b AK: Don't zero Variant data in the move constructor
There's no reason to zero the data that will be immediately overwritten.
2021-08-12 21:03:53 +02:00
Daniel Bertalan
39dd13fd17 AK: Destroy original value when assigning to Variant 2021-07-04 07:24:41 +04:30
Daniel Bertalan
515e2d9734 AK: Use conditionally trivial special member functions
This commit makes use of the conditionally trivial special member
functions introduced in C++20. Basically, `Optional` and `Variant`
inherits whether its wrapped type is trivially copy constructible,
trivially copy assignable or trivially destructible. This lets the
compiler optimize optimize a large number of their use cases.

The constraints have been applied to `Optional`'s converting
constructors too in order to make the API more explicit.

This feature is not supported by Clang yet, so we use conditional
compilation so that Lagom can be built on macOS. Once Clang has P0848R3
support, these can be removed.
2021-07-04 07:24:41 +04:30
Ali Mohammad Pur
745a1dbb5d AK: Add and use the RemoveCVReference<T> type trait 2021-06-28 01:08:41 +04:30
Ali Mohammad Pur
bda19a9ff3 AK: Add explicit Variant conversion operators
This allows converting between Variants of different types with less
pain.
2021-06-27 12:49:49 +01:00
Andreas Kling
beb43f673e AK: Undo bogus Variant::downcast() rename
I accidentally renamed these to verify_cast() when doing the global
AK::downcast() rename.
2021-06-26 21:27:58 +02:00
Andreas Kling
ee3a73ddbb AK: Rename downcast<T> => verify_cast<T>
This makes it much clearer what this cast actually does: it will
VERIFY that the thing we're casting is a T (using is<T>()).
2021-06-24 19:57:01 +02:00
Ali Mohammad Pur
8410d6aadb AK: Make a bunch of Variant methods ALWAYS_INLINE 2021-06-09 23:05:32 +04:30
Ali Mohammad Pur
ea7ba34a31 AK+LibWasm+LibJS: Disallow Variant.has() on types that aren't contained
Checking for this (and get()'ing it) is always invalid, so let's just
disallow it.
This also finds two bugs where the code is checking for types that can
never actually be in the variant (which was actually a refactor
artifact).
2021-06-02 18:02:47 +02:00
Ali Mohammad Pur
6b4d7b6c19 AK: Fix Variant construction from lvalue references
Fixes #7371 and appends its test cases.
2021-05-22 09:34:31 +02:00
Ali Mohammad Pur
3f350c3b65 AK: Remove [[gnu::noinline]] attribute from some variant members
These were left-overs from a debugging session :P
2021-05-22 09:34:31 +02:00
Lenny Maiorani
98468ae2d2 Variant: Remove redundant inline keyword
Problem:
- `constexpr inline` is redundant because `constexpr` implies `inline`.

Solution:
- Remove redundancy.
2021-05-20 18:58:18 +02:00
Timothy Flynn
145e246a5e AK: Allow AK::Variant::visit to return a value
This changes Variant::visit() to forward the value returned by the
selected visitor invocation. By perfectly forwarding the returned value,
this allows for the visitor to return by value or reference.

Note that all provided visitors must return the same type - the compiler
will otherwise fail with the message: "inconsistent deduction for auto
return type".
2021-05-19 20:41:09 +02:00
Linus Groh
0aab774343 Everywhere: Fix a bunch of typos 2021-05-17 17:48:55 +01:00
Ali Mohammad Pur
06a1c27e4d AK: Fix Variant's copy constructor trying to delegate to the wrong base
This was forgotten in 4fdbac2.
2021-05-13 19:44:32 +01:00
Ali Mohammad Pur
4fdbac236d AK/Variant: Deduplicate the contained types
This allows the construction of `Variant<int, int, int>`.
While this might not seem useful, it is very useful for making variants
that contain a series of member function pointers, which I plan to use
in LibGL for glGenLists() and co.
2021-05-11 14:09:17 +01:00
Ali Mohammad Pur
3038b6b7dc AK: Avoid the use of typeinfo in Variant
typeid() and RTTI was a nice clutch to implement this, but let's move
away from the horrible slowness and implement variants using type
indices for faster variants.
2021-05-11 14:09:17 +01:00
Ali Mohammad Pur
a51113c58e AK: Add a Variant<Ts...> implementation
Also adds an AK::Empty struct, because 'empty' variants are useful, but
this implementation leaves that to the user (i.e. a variant cannot
actually be empty, but it can contain an instance of Empty - i.e. a
byte).
Note that this is more of a constrained Any type, but they basically do
the same things anyway :^)
2021-05-05 19:02:51 +02:00