2020-08-03 21:14:37 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-08-03 21:14:37 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-11-07 16:40:10 +03:00
|
|
|
#include <AK/Forward.h>
|
2021-05-16 12:36:52 +03:00
|
|
|
#include <AK/IterationDecision.h>
|
2020-08-03 21:14:37 +03:00
|
|
|
#include <AK/StdLibExtras.h>
|
|
|
|
|
|
|
|
namespace AK::Concepts {
|
|
|
|
|
|
|
|
template<typename T>
|
2021-04-10 16:59:06 +03:00
|
|
|
concept Integral = IsIntegral<T>;
|
2020-08-03 21:14:37 +03:00
|
|
|
|
|
|
|
template<typename T>
|
2021-04-10 16:59:06 +03:00
|
|
|
concept FloatingPoint = IsFloatingPoint<T>;
|
2020-08-03 21:14:37 +03:00
|
|
|
|
2021-03-20 00:23:48 +03:00
|
|
|
template<typename T>
|
2021-04-10 16:59:06 +03:00
|
|
|
concept Arithmetic = IsArithmetic<T>;
|
2021-03-20 00:23:48 +03:00
|
|
|
|
2021-03-28 00:20:15 +03:00
|
|
|
template<typename T>
|
2021-04-10 16:59:06 +03:00
|
|
|
concept Signed = IsSigned<T>;
|
2021-03-28 00:20:15 +03:00
|
|
|
|
|
|
|
template<typename T>
|
2021-04-10 16:59:06 +03:00
|
|
|
concept Unsigned = IsUnsigned<T>;
|
2021-03-28 00:20:15 +03:00
|
|
|
|
2021-07-04 07:44:34 +03:00
|
|
|
template<typename T>
|
|
|
|
concept Enum = IsEnum<T>;
|
|
|
|
|
2021-05-16 12:36:52 +03:00
|
|
|
template<typename T, typename U>
|
|
|
|
concept SameAs = IsSame<T, U>;
|
|
|
|
|
2021-11-07 16:40:10 +03:00
|
|
|
template<typename T>
|
|
|
|
concept AnyString = Detail::IsConstructible<StringView, T>;
|
|
|
|
|
2021-11-07 16:50:41 +03:00
|
|
|
template<typename T, typename U>
|
|
|
|
concept HashCompatible = IsHashCompatible<Detail::Decay<T>, Detail::Decay<U>>;
|
|
|
|
|
2021-06-19 14:13:31 +03:00
|
|
|
// FIXME: remove once Clang formats these properly.
|
|
|
|
// clang-format off
|
2021-05-16 12:36:52 +03:00
|
|
|
template<typename Func, typename... Args>
|
|
|
|
concept VoidFunction = requires(Func func, Args... args)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
func(args...)
|
|
|
|
}
|
2021-06-19 14:13:31 +03:00
|
|
|
-> SameAs<void>;
|
2021-05-16 12:36:52 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
template<typename Func, typename... Args>
|
|
|
|
concept IteratorFunction = requires(Func func, Args... args)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
func(args...)
|
|
|
|
}
|
2021-06-19 14:13:31 +03:00
|
|
|
-> SameAs<IterationDecision>;
|
2021-05-16 12:36:52 +03:00
|
|
|
};
|
2021-07-22 17:37:17 +03:00
|
|
|
|
|
|
|
template<typename T, typename EndT>
|
|
|
|
concept IteratorPairWith = requires(T it, EndT end)
|
|
|
|
{
|
|
|
|
*it;
|
|
|
|
{ it != end } -> SameAs<bool>;
|
|
|
|
++it;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
concept IterableContainer = requires
|
|
|
|
{
|
|
|
|
{ declval<T>().begin() } -> IteratorPairWith<decltype(declval<T>().end())>;
|
|
|
|
};
|
|
|
|
|
2021-06-19 14:13:31 +03:00
|
|
|
// clang-format on
|
2020-08-03 21:14:37 +03:00
|
|
|
}
|
2020-12-06 01:25:19 +03:00
|
|
|
|
2021-03-28 00:24:50 +03:00
|
|
|
using AK::Concepts::Arithmetic;
|
2021-07-04 07:44:34 +03:00
|
|
|
using AK::Concepts::Enum;
|
2021-03-28 00:24:50 +03:00
|
|
|
using AK::Concepts::FloatingPoint;
|
|
|
|
using AK::Concepts::Integral;
|
2021-07-22 17:37:17 +03:00
|
|
|
using AK::Concepts::IterableContainer;
|
2021-05-16 12:36:52 +03:00
|
|
|
using AK::Concepts::IteratorFunction;
|
2021-07-22 17:37:17 +03:00
|
|
|
using AK::Concepts::IteratorPairWith;
|
2021-03-28 00:20:15 +03:00
|
|
|
using AK::Concepts::Signed;
|
|
|
|
using AK::Concepts::Unsigned;
|
2021-05-16 12:36:52 +03:00
|
|
|
using AK::Concepts::VoidFunction;
|