/* * Copyright (c) 2020, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include namespace AK::Concepts { template concept Integral = IsIntegral; template concept FloatingPoint = IsFloatingPoint; template concept Fundamental = IsFundamental; template concept Arithmetic = IsArithmetic; template concept Signed = IsSigned; template concept Unsigned = IsUnsigned; template concept Enum = IsEnum; template concept SameAs = IsSame; template concept OneOf = IsOneOf; template concept OneOfIgnoringCV = IsOneOfIgnoringCV; template typename S> concept SpecializationOf = IsSpecializationOf; template concept AnyString = IsConstructible; template concept HashCompatible = IsHashCompatible, Detail::Decay>; // FIXME: remove once Clang formats these properly. // clang-format off // Any indexable, sized, contiguous data structure. template concept ArrayLike = requires(ArrayT array, SizeT index) { { array[index] } -> SameAs&>; { array.size() } -> SameAs; { array.span() } -> SameAs>>; { array.data() } -> SameAs*>; }; // Any indexable data structure. template concept Indexable = requires(ArrayT array, SizeT index) { { array[index] } -> OneOf&, RemoveReference>; }; template concept VoidFunction = requires(Func func, Args... args) { { func(args...) } -> SameAs; }; template concept IteratorFunction = requires(Func func, Args... args) { { func(args...) } -> SameAs; }; template concept IteratorPairWith = requires(T it, EndT end) { *it; { it != end } -> SameAs; ++it; }; template concept IterableContainer = requires { { declval().begin() } -> IteratorPairWith().end())>; }; template concept FallibleFunction = requires(Func&& func, Args&&... args) { func(forward(args)...).is_error(); func(forward(args)...).release_error(); func(forward(args)...).release_value(); }; // clang-format on } #if !USING_AK_GLOBALLY namespace AK { #endif using AK::Concepts::Arithmetic; using AK::Concepts::ArrayLike; using AK::Concepts::Enum; using AK::Concepts::FallibleFunction; using AK::Concepts::FloatingPoint; using AK::Concepts::Fundamental; using AK::Concepts::Indexable; using AK::Concepts::Integral; using AK::Concepts::IterableContainer; using AK::Concepts::IteratorFunction; using AK::Concepts::IteratorPairWith; using AK::Concepts::OneOf; using AK::Concepts::OneOfIgnoringCV; using AK::Concepts::SameAs; using AK::Concepts::Signed; using AK::Concepts::SpecializationOf; using AK::Concepts::Unsigned; using AK::Concepts::VoidFunction; #if !USING_AK_GLOBALLY } #endif