2020-08-03 18:14:37 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-08-03 18:14:37 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-11-07 13:40:10 +00:00
|
|
|
#include <AK/Forward.h>
|
2021-05-16 09:36:52 +00:00
|
|
|
#include <AK/IterationDecision.h>
|
2020-08-03 18:14:37 +00:00
|
|
|
#include <AK/StdLibExtras.h>
|
|
|
|
|
|
|
|
namespace AK::Concepts {
|
|
|
|
|
|
|
|
template<typename T>
|
2021-04-10 13:59:06 +00:00
|
|
|
concept Integral = IsIntegral<T>;
|
2020-08-03 18:14:37 +00:00
|
|
|
|
|
|
|
template<typename T>
|
2021-04-10 13:59:06 +00:00
|
|
|
concept FloatingPoint = IsFloatingPoint<T>;
|
2020-08-03 18:14:37 +00:00
|
|
|
|
2022-02-22 21:04:24 +00:00
|
|
|
template<typename T>
|
|
|
|
concept Fundamental = IsFundamental<T>;
|
|
|
|
|
2021-03-19 21:23:48 +00:00
|
|
|
template<typename T>
|
2021-04-10 13:59:06 +00:00
|
|
|
concept Arithmetic = IsArithmetic<T>;
|
2021-03-19 21:23:48 +00:00
|
|
|
|
2021-03-27 21:20:15 +00:00
|
|
|
template<typename T>
|
2021-04-10 13:59:06 +00:00
|
|
|
concept Signed = IsSigned<T>;
|
2021-03-27 21:20:15 +00:00
|
|
|
|
|
|
|
template<typename T>
|
2021-04-10 13:59:06 +00:00
|
|
|
concept Unsigned = IsUnsigned<T>;
|
2021-03-27 21:20:15 +00:00
|
|
|
|
2021-07-04 04:44:34 +00:00
|
|
|
template<typename T>
|
|
|
|
concept Enum = IsEnum<T>;
|
|
|
|
|
2021-05-16 09:36:52 +00:00
|
|
|
template<typename T, typename U>
|
|
|
|
concept SameAs = IsSame<T, U>;
|
|
|
|
|
2023-01-19 01:29:39 +00:00
|
|
|
template<class From, class To>
|
|
|
|
concept ConvertibleTo = IsConvertible<From, To>;
|
|
|
|
|
2022-03-28 11:52:00 +00:00
|
|
|
template<typename U, typename... Ts>
|
|
|
|
concept OneOf = IsOneOf<U, Ts...>;
|
|
|
|
|
2022-04-17 04:51:55 +00:00
|
|
|
template<typename U, typename... Ts>
|
|
|
|
concept OneOfIgnoringCV = IsOneOfIgnoringCV<U, Ts...>;
|
|
|
|
|
2022-02-14 13:18:51 +00:00
|
|
|
template<typename T, template<typename...> typename S>
|
|
|
|
concept SpecializationOf = IsSpecializationOf<T, S>;
|
|
|
|
|
2022-12-06 22:02:58 +00:00
|
|
|
template<typename T, typename S>
|
|
|
|
concept DerivedFrom = IsBaseOf<S, T>;
|
|
|
|
|
2021-11-07 13:40:10 +00:00
|
|
|
template<typename T>
|
2023-02-02 15:48:11 +00:00
|
|
|
concept AnyString = IsConstructible<StringView, RemoveCVReference<T> const&>;
|
2021-11-07 13:40:10 +00:00
|
|
|
|
2021-11-07 13:50:41 +00:00
|
|
|
template<typename T, typename U>
|
|
|
|
concept HashCompatible = IsHashCompatible<Detail::Decay<T>, Detail::Decay<U>>;
|
|
|
|
|
2022-01-27 11:53:52 +00:00
|
|
|
// Any indexable, sized, contiguous data structure.
|
|
|
|
template<typename ArrayT, typename ContainedT, typename SizeT = size_t>
|
2023-07-08 02:59:01 +00:00
|
|
|
concept ArrayLike = requires(ArrayT array, SizeT index) {
|
2022-01-27 11:53:52 +00:00
|
|
|
{
|
|
|
|
array[index]
|
|
|
|
}
|
|
|
|
-> SameAs<RemoveReference<ContainedT>&>;
|
|
|
|
|
|
|
|
{
|
|
|
|
array.size()
|
|
|
|
}
|
|
|
|
-> SameAs<SizeT>;
|
|
|
|
|
|
|
|
{
|
|
|
|
array.span()
|
|
|
|
}
|
|
|
|
-> SameAs<Span<RemoveReference<ContainedT>>>;
|
|
|
|
|
|
|
|
{
|
|
|
|
array.data()
|
|
|
|
}
|
|
|
|
-> SameAs<RemoveReference<ContainedT>*>;
|
|
|
|
};
|
|
|
|
|
2022-04-21 08:41:27 +00:00
|
|
|
// Any indexable data structure.
|
|
|
|
template<typename ArrayT, typename ContainedT, typename SizeT = size_t>
|
2023-07-08 02:59:01 +00:00
|
|
|
concept Indexable = requires(ArrayT array, SizeT index) {
|
2022-04-21 08:41:27 +00:00
|
|
|
{
|
|
|
|
array[index]
|
|
|
|
}
|
|
|
|
-> OneOf<RemoveReference<ContainedT>&, RemoveReference<ContainedT>>;
|
|
|
|
};
|
|
|
|
|
2021-05-16 09:36:52 +00:00
|
|
|
template<typename Func, typename... Args>
|
2023-07-08 02:59:01 +00:00
|
|
|
concept VoidFunction = requires(Func func, Args... args) {
|
2021-05-16 09:36:52 +00:00
|
|
|
{
|
|
|
|
func(args...)
|
|
|
|
}
|
2021-06-19 11:13:31 +00:00
|
|
|
-> SameAs<void>;
|
2021-05-16 09:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template<typename Func, typename... Args>
|
2023-07-08 02:59:01 +00:00
|
|
|
concept IteratorFunction = requires(Func func, Args... args) {
|
2021-05-16 09:36:52 +00:00
|
|
|
{
|
|
|
|
func(args...)
|
|
|
|
}
|
2021-06-19 11:13:31 +00:00
|
|
|
-> SameAs<IterationDecision>;
|
2021-05-16 09:36:52 +00:00
|
|
|
};
|
2021-07-22 14:37:17 +00:00
|
|
|
|
|
|
|
template<typename T, typename EndT>
|
2023-07-08 02:59:01 +00:00
|
|
|
concept IteratorPairWith = requires(T it, EndT end) {
|
2021-07-22 14:37:17 +00:00
|
|
|
*it;
|
2023-07-08 02:59:01 +00:00
|
|
|
{
|
|
|
|
it != end
|
|
|
|
} -> SameAs<bool>;
|
2021-07-22 14:37:17 +00:00
|
|
|
++it;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
2023-07-08 02:59:01 +00:00
|
|
|
concept IterableContainer = requires {
|
|
|
|
{
|
|
|
|
declval<T>().begin()
|
|
|
|
} -> IteratorPairWith<decltype(declval<T>().end())>;
|
2021-07-22 14:37:17 +00:00
|
|
|
};
|
|
|
|
|
2022-11-17 12:52:39 +00:00
|
|
|
template<typename Func, typename... Args>
|
|
|
|
concept FallibleFunction = requires(Func&& func, Args&&... args) {
|
|
|
|
func(forward<Args>(args)...).is_error();
|
|
|
|
func(forward<Args>(args)...).release_error();
|
|
|
|
func(forward<Args>(args)...).release_value();
|
|
|
|
};
|
|
|
|
|
2023-07-08 10:38:25 +00:00
|
|
|
}
|
|
|
|
namespace AK::Detail {
|
|
|
|
|
|
|
|
template<typename T, typename Out, typename... Args>
|
|
|
|
inline constexpr bool IsCallableWithArguments = requires(T t) {
|
|
|
|
{
|
|
|
|
t(declval<Args>()...)
|
|
|
|
} -> Concepts::ConvertibleTo<Out>;
|
|
|
|
} || requires(T t) {
|
|
|
|
{
|
|
|
|
t(declval<Args>()...)
|
|
|
|
} -> Concepts::SameAs<Out>;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace AK {
|
|
|
|
|
|
|
|
using Detail::IsCallableWithArguments;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace AK::Concepts {
|
|
|
|
|
|
|
|
template<typename Func, typename R, typename... Args>
|
|
|
|
concept CallableAs = Detail::IsCallableWithArguments<Func, R, Args...>;
|
|
|
|
|
2020-08-03 18:14:37 +00:00
|
|
|
}
|
2020-12-05 22:25:19 +00:00
|
|
|
|
2022-11-27 15:35:35 +00:00
|
|
|
#if !USING_AK_GLOBALLY
|
|
|
|
namespace AK {
|
|
|
|
#endif
|
2021-03-27 21:24:50 +00:00
|
|
|
using AK::Concepts::Arithmetic;
|
2022-01-27 11:53:52 +00:00
|
|
|
using AK::Concepts::ArrayLike;
|
2023-07-08 10:38:25 +00:00
|
|
|
using AK::Concepts::CallableAs;
|
2023-01-19 01:29:39 +00:00
|
|
|
using AK::Concepts::ConvertibleTo;
|
2022-12-06 22:02:58 +00:00
|
|
|
using AK::Concepts::DerivedFrom;
|
2021-07-04 04:44:34 +00:00
|
|
|
using AK::Concepts::Enum;
|
2022-11-17 12:52:39 +00:00
|
|
|
using AK::Concepts::FallibleFunction;
|
2021-03-27 21:24:50 +00:00
|
|
|
using AK::Concepts::FloatingPoint;
|
2022-02-22 21:04:24 +00:00
|
|
|
using AK::Concepts::Fundamental;
|
2022-04-21 08:41:27 +00:00
|
|
|
using AK::Concepts::Indexable;
|
2021-03-27 21:24:50 +00:00
|
|
|
using AK::Concepts::Integral;
|
2021-07-22 14:37:17 +00:00
|
|
|
using AK::Concepts::IterableContainer;
|
2021-05-16 09:36:52 +00:00
|
|
|
using AK::Concepts::IteratorFunction;
|
2021-07-22 14:37:17 +00:00
|
|
|
using AK::Concepts::IteratorPairWith;
|
2022-03-28 11:52:00 +00:00
|
|
|
using AK::Concepts::OneOf;
|
2022-04-17 04:51:55 +00:00
|
|
|
using AK::Concepts::OneOfIgnoringCV;
|
2022-01-27 12:44:53 +00:00
|
|
|
using AK::Concepts::SameAs;
|
2021-03-27 21:20:15 +00:00
|
|
|
using AK::Concepts::Signed;
|
2022-02-14 13:18:51 +00:00
|
|
|
using AK::Concepts::SpecializationOf;
|
2021-03-27 21:20:15 +00:00
|
|
|
using AK::Concepts::Unsigned;
|
2021-05-16 09:36:52 +00:00
|
|
|
using AK::Concepts::VoidFunction;
|
2022-11-27 15:35:35 +00:00
|
|
|
#if !USING_AK_GLOBALLY
|
|
|
|
}
|
2022-11-26 11:18:30 +00:00
|
|
|
#endif
|