summaryrefslogtreecommitdiff
path: root/AK/Optional.h
AgeCommit message (Collapse)Author
2020-05-16AK: Remove experimental clang -Wconsumed stuffAndreas Kling
This stopped working quite some time ago due to Clang losing track of typestates for some reason and everything becoming "unknown". Since we're primarily using GCC anyway, it doesn't seem worth it to try and maintain this non-working experiment for a secondary compiler. Also it doesn't look like the Clang team is actively maintaining this flag anyway. So good-bye, -Wconsumed. :/
2020-04-30AK: Add ALWAYS_INLINE, NEVER_INLINE and FLATTEN macrosAndreas Kling
It's tedious to write (and look at) [[gnu::always_inline]] etc. :^)
2020-04-12AK: Inline Optional functions more aggressivelyAndreas Kling
This turns into much less code in the most common cases, here's why: The normal Optional usage pattern is something like: auto foo = get_me_an_optional(); if (foo.has_value()) do_stuff_with(foo.value()); In this typical scenario, we check has_value() before calling value(). Without inlining, value() will double-check has_value() itself and assert if it fails. Inlining allows the compiler to optimize all of this away.
2020-03-08AK: Move memory stuff (fast memcpy, etc) to a separate headerAndreas Kling
Move the "fast memcpy" stuff out of StdLibExtras.h and into Memory.h. This will break a ton of things that were relying on StdLibExtras.h to include a bunch of other headers. Fix will follow immediately after. This makes it possible to include StdLibExtras.h from Types.h, which is the main point of this exercise.
2020-03-08AK: Use __builtin_memset() and such to reduce header dependenciesAndreas Kling
We can use __builtin_memset() without including <string.h>. This is pretty neat, as it will allow us to reduce the header deps of AK templates a bit, if applied consistently. Note that this is an enabling change for an upcoming #include removal.
2020-03-06AK: Remove Optional::operator bool()Andreas Kling
This was causing some obvious-in-hindsight but hard to spot bugs where we'd implicitly convert the bool to an integer type and carry on with the number 1 instead of the actual value().
2020-02-24AK: Zero-initialize the internal storage of OptionalAndreas Kling
2020-02-14LibCore: Add a forward declaration headerAndreas Kling
This patch adds <LibCore/Forward.h> and uses it in various places to shrink the header dependency graph.
2020-02-06AK: Add missing StdLibExtras.h include in Optional.hAndreas Kling
2020-01-18Meta: Add license header to source filesAndreas Kling
As suggested by Joshua, this commit adds the 2-clause BSD license as a comment block to the top of every source file. For the first pass, I've just added myself for simplicity. I encourage everyone to add themselves as copyright holders of any file they've added or modified in some significant way. If I've added myself in error somewhere, feel free to replace it with the appropriate copyright holder instead. Going forward, all new source files should include a license header.
2019-08-25AK: Optional::operator bool() should consume the OptionalAndreas Kling
We use consumable annotations to catch bugs where you get the .value() of an Optional before verifying that it's okay. The bug here was that only has_value() would set the consumed state, even though operator bool() does the same job.
2019-08-08AK: Add Optional<T>(const U&)Andreas Kling
This replaces Optional<T>(U&&) which clang-tidy complained may hide the regular copy and move constructors. That's a good point, clang-tidy, and I appreciate you pointing that out!
2019-08-07AK: Fix -Wconsumed warnings in Optional move-ctor and move-assignAndreas Kling
Our protocol says we have to call has_value() before release_value(). The code was already safe, but the compiler had no way of knowing that.
2019-08-05AK: Fix leak in Optional(Optional&&)Andreas Kling
We were *copying* the other Optional's value and then marking it as not having a value. This prevented us from ever destroying the original.
2019-08-05AK: Optional::operator=(Optional&&) should clear movee's has_value bitAndreas Kling
We were forgetting to clear m_has_value in the Optional being moved from when using operator=(Optional&&).
2019-07-31Optional: Add consumable checksRobin Burchell
These will, when building with clang, prevent using Optional::value without first checking Optional::has_value() - at compile time.
2019-07-24AK: Make HashMap::get(Key) return an Optional<Value>.Andreas Kling
This allows HashMap::get() to be used for value types that cannot be default constructed (e.g NonnullOwnPtr.)
2019-07-24AK: Add Optional::value_or(T).Andreas Kling
This is like value() but with a fallback in case there's no value set.
2019-07-08AK: Add a simple Optional<T> template.Andreas Kling
This can be used to store any type, with a flag that says if any value is present or not.