serenity/AK/Concepts.h
Daniel Bertalan 985adcca38 AK: Make C++ concepts support mandatory for compilers
The latest GCC and Clang versions both support this, so we can freely
use these in our code.
2021-06-24 17:35:49 +04:30

61 lines
1.2 KiB
C++

/*
* Copyright (c) 2020, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/IterationDecision.h>
#include <AK/StdLibExtras.h>
namespace AK::Concepts {
template<typename T>
concept Integral = IsIntegral<T>;
template<typename T>
concept FloatingPoint = IsFloatingPoint<T>;
template<typename T>
concept Arithmetic = IsArithmetic<T>;
template<typename T>
concept Signed = IsSigned<T>;
template<typename T>
concept Unsigned = IsUnsigned<T>;
template<typename T, typename U>
concept SameAs = IsSame<T, U>;
// FIXME: remove once Clang formats these properly.
// clang-format off
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>;
};
// clang-format on
}
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;