mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-09 09:34:57 +09:00
AK+Kernel+LibELF: Remove the need for IteratorDecision::Continue
By constraining two implementations, the compiler will select the best fitting one. All this will require is duplicating the implementation and simplifying for the `void` case. This constraining also informs both the caller and compiler by passing the callback parameter types as part of the constraint (e.g.: `IterationFunction<int>`). Some `for_each` functions in LibELF only take functions which return `void`. This is a minimal correctness check, as it removes one way for a function to incompletely do something. There seems to be a possible idiom where inside a lambda, a `return;` is the same as `continue;` in a for-loop.
This commit is contained in:
parent
bbaa463032
commit
aa4d41fe2c
Notes:
sideshowbarker
2024-07-18 18:03:26 +09:00
Author: https://github.com/Nicholas-Baron
Commit: aa4d41fe2c
Pull-request: https://github.com/SerenityOS/serenity/pull/6445
Reviewed-by: https://github.com/Hendiadyoin1
Reviewed-by: https://github.com/alimpfard
Reviewed-by: https://github.com/linusg
25 changed files with 311 additions and 127 deletions
|
@ -6,6 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/IterationDecision.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
|
||||
namespace AK::Concepts {
|
||||
|
@ -27,6 +28,27 @@ concept Signed = IsSigned<T>;
|
|||
template<typename T>
|
||||
concept Unsigned = IsUnsigned<T>;
|
||||
|
||||
template<typename T, typename U>
|
||||
concept SameAs = IsSame<T, U>;
|
||||
|
||||
template<typename Func, typename... Args>
|
||||
concept VoidFunction = requires(Func func, Args... args)
|
||||
{
|
||||
{
|
||||
func(args...)
|
||||
}
|
||||
->SameAs<void>;
|
||||
};
|
||||
|
||||
template<typename Func, typename... Args>
|
||||
concept IteratorFunction = requires(Func func, Args... args)
|
||||
{
|
||||
{
|
||||
func(args...)
|
||||
}
|
||||
->SameAs<IterationDecision>;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
@ -36,7 +58,9 @@ concept Unsigned = IsUnsigned<T>;
|
|||
using AK::Concepts::Arithmetic;
|
||||
using AK::Concepts::FloatingPoint;
|
||||
using AK::Concepts::Integral;
|
||||
using AK::Concepts::IteratorFunction;
|
||||
using AK::Concepts::Signed;
|
||||
using AK::Concepts::Unsigned;
|
||||
using AK::Concepts::VoidFunction;
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue