summaryrefslogtreecommitdiff
path: root/AK/Variant.h
AgeCommit message (Collapse)Author
2021-07-04AK: Destroy original value when assigning to VariantDaniel Bertalan
2021-07-04AK: Use conditionally trivial special member functionsDaniel Bertalan
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-06-28AK: Add and use the RemoveCVReference<T> type traitAli Mohammad Pur
2021-06-27AK: Add explicit Variant conversion operatorsAli Mohammad Pur
This allows converting between Variants of different types with less pain.
2021-06-26AK: Undo bogus Variant::downcast() renameAndreas Kling
I accidentally renamed these to verify_cast() when doing the global AK::downcast() rename.
2021-06-24AK: Rename downcast<T> => verify_cast<T>Andreas Kling
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-09AK: Make a bunch of Variant methods ALWAYS_INLINEAli Mohammad Pur
2021-06-02AK+LibWasm+LibJS: Disallow Variant.has() on types that aren't containedAli Mohammad Pur
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-05-22AK: Fix Variant construction from lvalue referencesAli Mohammad Pur
Fixes #7371 and appends its test cases.
2021-05-22AK: Remove [[gnu::noinline]] attribute from some variant membersAli Mohammad Pur
These were left-overs from a debugging session :P
2021-05-20Variant: Remove redundant inline keywordLenny Maiorani
Problem: - `constexpr inline` is redundant because `constexpr` implies `inline`. Solution: - Remove redundancy.
2021-05-19AK: Allow AK::Variant::visit to return a valueTimothy Flynn
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-17Everywhere: Fix a bunch of typosLinus Groh
2021-05-13AK: Fix Variant's copy constructor trying to delegate to the wrong baseAli Mohammad Pur
This was forgotten in 4fdbac2.
2021-05-11AK/Variant: Deduplicate the contained typesAli Mohammad Pur
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-11AK: Avoid the use of typeinfo in VariantAli Mohammad Pur
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-05AK: Add a Variant<Ts...> implementationAli Mohammad Pur
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 :^)