basedOpinionated utility library |
git clone git://git.dimitrijedobrota.com/based.git |
Log | Files | Refs | README | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING | |
commit | 301e6b5c5e5860b347ebd8dd29b964bdf9016e3d |
parent | 4f51a55ccbbcc56f52cdc519108261e7a0f68027 |
author | Dimitrije Dobrota <mail@dimitrijedobrota.com> |
date | Wed, 26 Mar 2025 12:49:51 +0100 |
Hide parts in detail namespace
Diffstat:M | example/type_traits.cpp | | | ++ |
M | include/based/type_traits.hpp | | | ++++++++++++++++++--------------------------- |
2 files changed, 20 insertions(+), 27 deletions(-)
diff --git a/example/type_traits.cpp b/example/type_traits.cpp
@@ -112,4 +112,6 @@ int main()
static_assert(based::Procedure<decltype(l2)>);
static_assert(!based::RegularProcedure<decltype(l2)>);
static_assert(!based::FunctionalProcedure<decltype(l2)>);
return 0;
}
diff --git a/include/based/type_traits.hpp b/include/based/type_traits.hpp
@@ -1,5 +1,6 @@
#pragma once
#include <cstdint>
#include <tuple>
#include <type_traits>
@@ -20,8 +21,8 @@ concept Input =
|| (std::is_lvalue_reference_v<T>
&& std::is_const_v<std::remove_reference_t<T>>);
template<typename P, typename... Args>
concept Invokable = std::invocable<P, Args...>;
namespace detail
{
template<typename Fun>
concept FreeProcedure = std::is_function_v<Fun>;
@@ -33,10 +34,6 @@ template<typename Fun>
concept FunctorProcedure = std::is_class_v<std::decay_t<Fun>>
&& requires(Fun&& t) { &std::decay_t<Fun>::operator(); };
template<typename P>
concept Procedure =
FreeProcedure<P> || MemberProcedure<P> || FunctorProcedure<P>;
template<class>
struct is_regular_tuple : std::false_type
{
@@ -162,9 +159,6 @@ struct domain<P>
using type = signature<std::decay_t<P>>::arg_type;
};
template<typename P>
using domain_t = domain<P>::type;
template<typename>
struct codomain;
@@ -186,57 +180,54 @@ struct codomain<P>
using type = signature<std::decay_t<P>>::ret_type;
};
} // namespace detail
template<typename P>
using codomain_t = typename codomain<P>::type;
using domain_t = detail::domain<P>::type;
template<typename P>
struct arity
{
static constexpr auto value = std::tuple_size<domain_t<P>>::value;
};
using codomain_t = typename detail::codomain<P>::type;
template<typename P>
inline constexpr auto arity_v = arity<P>::value;
inline constexpr auto arity_v = std::tuple_size<domain_t<P>>::value;
template<typename P, std::size_t Idx>
requires requires { Idx < arity_v<P>; }
struct domain_elem
{
using type = std::tuple_element_t<Idx, domain_t<P>>;
};
using domain_elem_t = std::tuple_element_t<Idx, domain_t<P>>;
template<typename P, std::size_t Idx>
using domain_elem_t = typename domain_elem<P, Idx>::type;
template<typename P>
concept Procedure = detail::FreeProcedure<P> || detail::MemberProcedure<P>
|| detail::FunctorProcedure<P>;
template<typename P>
concept RegularProcedure = requires {
requires(Procedure<P>);
requires(RegularTuple<domain_t<P>>);
requires(detail::RegularTuple<domain_t<P>>);
requires(Regular<codomain_t<P>>);
};
template<typename P>
concept FunctionalProcedure = requires {
requires(RegularProcedure<P>);
requires(InputTuple<domain_t<P>>);
requires(detail::InputTuple<domain_t<P>>);
};
template<typename P>
concept UnaryFunction = requires {
requires(FunctorProcedure<P>);
requires(FunctionalProcedure<P>);
requires(arity_v<P> == 1);
};
template<typename P>
concept HomogeneousFunction = requires {
requires(FunctorProcedure<P>);
requires(FunctionalProcedure<P>);
requires(arity_v<P> > 0);
requires(HomogenousTuple<domain_t<P>>);
requires(detail::HomogenousTuple<domain_t<P>>);
};
template<typename P>
concept Predicate = requires {
requires(FunctorProcedure<P>);
requires(FunctionalProcedure<P>);
requires(std::same_as<bool, codomain_t<P>>);
};