Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@

# Update format to 120 columns PR #24
76d220e6f702935decdb347faa40364d83e69be1
# Update format to clang-18 PR #79
98a2378fca873bc2e019548d72732a15715bae36
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ jobs:
--slave /usr/bin/gcc-nm gcc-nm /usr/local/bin/gcc-nm \
--slave /usr/bin/gcc-ranlib gcc-ranlib /usr/local/bin/gcc-ranlib \
--slave /usr/bin/gcov gcov /usr/local/bin/gcov \
--slave /usr/bin/gcov-tool gcov-tool /usr/local/bin/gcov-dump \
--slave /usr/bin/gcov-dump gcov-dump /usr/local/bin/gcov-tool \
--slave /usr/bin/gcov-tool gcov-tool /usr/local/bin/gcov-tool \
--slave /usr/bin/gcov-dump gcov-dump /usr/local/bin/gcov-dump \
--slave /usr/bin/lto-dump lto-dump /usr/local/bin/lto-dump
update-alternatives --auto gcc

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
format-check:
runs-on: ubuntu-22.04
env:
CLANG_VERSION: 17
CLANG_VERSION: 18
steps:
- uses: actions/checkout@v4

Expand Down
31 changes: 17 additions & 14 deletions include/functional/detail/functional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ template <typename Fn, typename... Args>

template <typename Fn, typename Arg, typename... Args>
requires(_some_pack<Arg> || _some_sum<Arg>)
&& ((sizeof...(Args) == 0) || (not(... || (_some_pack<Args> || _some_sum<Args>))))
&& requires(Fn &&fn, Arg &&arg, Args &&...args) { FWD(arg).invoke(FWD(fn), FWD(args)...); }
&& ((sizeof...(Args) == 0) || (not(... || (_some_pack<Args> || _some_sum<Args>))))
&& requires(Fn &&fn, Arg &&arg, Args &&...args) { FWD(arg).invoke(FWD(fn), FWD(args)...); }
[[nodiscard]] constexpr auto invoke(Fn &&fn, Arg &&arg, Args &&...args) -> decltype(auto)

{
Expand All @@ -84,10 +84,10 @@ template <typename Fn, typename Arg, typename... Args>

template <typename Fn, typename Arg, typename Arg0, typename... Args>
requires((_some_pack<Arg0> || _some_sum<Arg0>) || ... || (_some_pack<Args> || _some_sum<Args>))
&& requires(Fn &&fn, Arg &&arg, Arg0 &&arg0, Args &&...args) {
invoke<Fn, decltype(::fn::detail::_fold_detail::fold<Arg, Arg0>(FWD(arg), FWD(arg0))), Args...>(
FWD(fn), ::fn::detail::_fold_detail::fold<Arg, Arg0>(FWD(arg), FWD(arg0)), FWD(args)...);
}
&& requires(Fn &&fn, Arg &&arg, Arg0 &&arg0, Args &&...args) {
invoke<Fn, decltype(::fn::detail::_fold_detail::fold<Arg, Arg0>(FWD(arg), FWD(arg0))), Args...>(
FWD(fn), ::fn::detail::_fold_detail::fold<Arg, Arg0>(FWD(arg), FWD(arg0)), FWD(args)...);
}
[[nodiscard]] constexpr auto invoke(Fn &&fn, Arg &&arg, Arg0 &&arg0, Args &&...args) -> decltype(auto)
{
using type = decltype(::fn::detail::_fold_detail::fold<Arg, Arg0>(FWD(arg), FWD(arg0)));
Expand All @@ -104,19 +104,22 @@ template <typename Ret, typename Fn, typename... Args>

template <typename Ret, typename Fn, typename Arg, typename... Args>
requires(_some_pack<Arg> || _some_sum<Arg>)
&& ((sizeof...(Args) == 0) || (not(... || (_some_pack<Args> || _some_sum<Args>))))
&& requires(Fn &&fn, Arg &&arg, Args &&...args) { FWD(arg).template invoke_r<Ret>(FWD(fn), FWD(args)...); }
&& ((sizeof...(Args) == 0) || (not(... || (_some_pack<Args> || _some_sum<Args>))))
&& requires(Fn &&fn, Arg &&arg, Args &&...args) {
FWD(arg).template invoke_r<Ret>(FWD(fn), FWD(args)...);
}
[[nodiscard]] constexpr auto invoke_r(Fn &&fn, Arg &&arg, Args &&...args) -> decltype(auto)
{
return FWD(arg).template invoke_r<Ret>(FWD(fn), FWD(args)...);
}

template <typename Ret, typename Fn, typename Arg, typename Arg0, typename... Args>
requires((_some_pack<Arg0> || _some_sum<Arg0>) || ... || (_some_pack<Args> || _some_sum<Args>))
&& requires(Fn &&fn, Arg &&arg, Arg0 &&arg0, Args &&...args) {
invoke_r<Ret, Fn, decltype(::fn::detail::_fold_detail::fold<Arg, Arg0>(FWD(arg), FWD(arg0))), Args...>(
FWD(fn), ::fn::detail::_fold_detail::fold<Arg, Arg0>(FWD(arg), FWD(arg0)), FWD(args)...);
}
&& requires(Fn &&fn, Arg &&arg, Arg0 &&arg0, Args &&...args) {
invoke_r<Ret, Fn, decltype(::fn::detail::_fold_detail::fold<Arg, Arg0>(FWD(arg), FWD(arg0))),
Args...>(FWD(fn), ::fn::detail::_fold_detail::fold<Arg, Arg0>(FWD(arg), FWD(arg0)),
FWD(args)...);
}
[[nodiscard]] constexpr auto invoke_r(Fn &&fn, Arg &&arg, Arg0 &&arg0, Args &&...args) -> decltype(auto)
{
using type = decltype(::fn::detail::_fold_detail::fold<Arg, Arg0>(FWD(arg), FWD(arg0)));
Expand Down Expand Up @@ -152,8 +155,8 @@ template <typename Fn, typename... Args> struct _is_invocable {
template <typename Ret, typename Fn, typename... Args>
constexpr auto _is_invocable_r_result(
Fn &&, Args &&...,
std::type_identity<decltype(_invoke_detail::invoke_r<Ret>(std::declval<Fn>(), std::declval<Args>()...))> = {})
-> std::true_type;
std::type_identity<decltype(_invoke_detail::invoke_r<Ret>(std::declval<Fn>(), std::declval<Args>()...))>
= {}) -> std::true_type;
template <typename Ret, typename Fn, typename... Args>
constexpr auto _is_invocable_r_result(auto &&...) -> std::false_type;
template <typename Ret, typename Fn, typename... Args> struct _is_invocable_r {
Expand Down
4 changes: 2 additions & 2 deletions include/functional/detail/meta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ template <typename... Ts> struct normalized final {
static constexpr _uniqued _indices_v = _indices();

template <template <typename...> typename F, std::size_t... Is>
static constexpr auto _normalized_f(std::index_sequence<Is...> const &)
-> F<select_nth_t<_indices_v.indices[Is], Ts...>...>;
static constexpr auto
_normalized_f(std::index_sequence<Is...> const &) -> F<select_nth_t<_indices_v.indices[Is], Ts...>...>;

// How many unique types
static constexpr std::size_t size = _indices_v.size;
Expand Down
13 changes: 7 additions & 6 deletions include/functional/detail/pack_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,20 @@ template <std::size_t... Is, typename... Ts> struct pack_impl<std::index_sequenc

template <typename Self, typename Fn, typename... Args>
requires(not(... || (_some_pack<Args> || _some_sum<Args>)))
static constexpr auto _swap_invoke(Self &&self, Fn &&fn, Args &&...args) noexcept
-> ::std::invoke_result<decltype(fn), decltype(args)..., apply_const_lvalue_t<Self, Ts &&>...>::type
requires(::std::is_invocable<decltype(fn), decltype(args)..., apply_const_lvalue_t<Self, Ts &&>...>::value)
static constexpr auto _swap_invoke(Self &&self, Fn &&fn, Args &&...args) noexcept
-> ::std::invoke_result<decltype(fn), decltype(args)..., apply_const_lvalue_t<Self, Ts &&>...>::type
requires(
::std::is_invocable<decltype(fn), decltype(args)..., apply_const_lvalue_t<Self, Ts &&>...>::value)
{
return ::std::invoke(FWD(fn), FWD(args)...,
static_cast<apply_const_lvalue_t<Self, Ts &&>>(FWD(self)._element<Is, Ts>::v)...);
}

template <typename Self, typename Fn, typename... Args>
requires(not(... || (_some_pack<Args> || _some_sum<Args>)))
static constexpr auto _invoke(Self &&self, Fn &&fn, Args &&...args) noexcept
-> _invoke_result<decltype(fn), apply_const_lvalue_t<Self, Ts &&>..., decltype(args)...>::type
requires(_is_invocable<decltype(fn), apply_const_lvalue_t<Self, Ts &&>..., decltype(args)...>::value)
static constexpr auto _invoke(Self &&self, Fn &&fn, Args &&...args) noexcept
-> _invoke_result<decltype(fn), apply_const_lvalue_t<Self, Ts &&>..., decltype(args)...>::type
requires(_is_invocable<decltype(fn), apply_const_lvalue_t<Self, Ts &&>..., decltype(args)...>::value)
{
return ::fn::detail::_invoke(
FWD(fn), static_cast<apply_const_lvalue_t<Self, Ts &&>>(FWD(self)._element<Is, Ts>::v)..., FWD(args)...);
Expand Down
31 changes: 16 additions & 15 deletions include/functional/detail/variadic_union.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ template <typename T, typename Ret, typename... Args>
}

template <typename T, typename Fn, typename... Args>
constexpr auto _is_type_invocable_result(
Fn &&, Args &&..., std::type_identity<decltype(_invoke_type<T>(std::declval<Fn>(), std::declval<Args>()...))> = {})
-> std::true_type;
constexpr auto
_is_type_invocable_result(Fn &&, Args &&...,
std::type_identity<decltype(_invoke_type<T>(std::declval<Fn>(), std::declval<Args>()...))>
= {}) -> std::true_type;
template <typename T, typename Fn, typename... Args>
constexpr auto _is_type_invocable_result(auto &&...) -> std::false_type;

Expand Down Expand Up @@ -73,8 +74,8 @@ concept _typelist_type_invocable = _is_tst_invocable<Fn, T &&>;
template <typename T, typename Ret, typename Fn, typename... Args>
constexpr auto _is_type_invocable_r_result(
Fn &&, Args &&...,
std::type_identity<decltype(_invoke_type_r<T, Ret>(std::declval<Fn>(), std::declval<Args>()...))> = {})
-> std::true_type;
std::type_identity<decltype(_invoke_type_r<T, Ret>(std::declval<Fn>(), std::declval<Args>()...))>
= {}) -> std::true_type;
template <typename T, typename Ret, typename Fn, typename... Args>
constexpr auto _is_type_invocable_r_result(auto &&...) -> std::false_type;
template <typename T, typename Ret, typename Fn, typename... Args> struct _is_type_invocable_r {
Expand Down Expand Up @@ -230,40 +231,40 @@ union variadic_union<T0, T1, T2, T3, Ts...> final {

template <typename T, typename U>
[[nodiscard]] constexpr auto *ptr_variadic_union(some_variadic_union auto &&v) noexcept
requires std::is_same_v<std::remove_cvref_t<decltype(v)>, U>
&& (U::template has_type<T>) && std::is_same_v<T, typename U::t0>
requires std::is_same_v<std::remove_cvref_t<decltype(v)>, U> && (U::template has_type<T>)
&& std::is_same_v<T, typename U::t0>
{
return &v.v0;
}

template <typename T, typename U>
[[nodiscard]] constexpr auto *ptr_variadic_union(some_variadic_union auto &&v) noexcept
requires std::is_same_v<std::remove_cvref_t<decltype(v)>, U>
&& (U::template has_type<T>) && std::is_same_v<T, typename U::t1>
requires std::is_same_v<std::remove_cvref_t<decltype(v)>, U> && (U::template has_type<T>)
&& std::is_same_v<T, typename U::t1>
{
return &v.v1;
}

template <typename T, typename U>
[[nodiscard]] constexpr auto *ptr_variadic_union(some_variadic_union auto &&v) noexcept
requires std::is_same_v<std::remove_cvref_t<decltype(v)>, U>
&& (U::template has_type<T>) && std::is_same_v<T, typename U::t2>
requires std::is_same_v<std::remove_cvref_t<decltype(v)>, U> && (U::template has_type<T>)
&& std::is_same_v<T, typename U::t2>
{
return &v.v2;
}

template <typename T, typename U>
[[nodiscard]] constexpr auto *ptr_variadic_union(some_variadic_union auto &&v) noexcept
requires std::is_same_v<std::remove_cvref_t<decltype(v)>, U>
&& (U::template has_type<T>) && std::is_same_v<T, typename U::t3>
requires std::is_same_v<std::remove_cvref_t<decltype(v)>, U> && (U::template has_type<T>)
&& std::is_same_v<T, typename U::t3>
{
return &v.v3;
}

template <typename T, typename U>
[[nodiscard]] constexpr auto *ptr_variadic_union(some_variadic_union auto &&v) noexcept
requires std::is_same_v<std::remove_cvref_t<decltype(v)>, U>
&& (U::template has_type<T>) && (U::more_t::template has_type<T>)
requires std::is_same_v<std::remove_cvref_t<decltype(v)>, U> && (U::template has_type<T>)
&& (U::more_t::template has_type<T>)
{
return ptr_variadic_union<T, typename U::more_t>(v.more);
}
Expand Down
16 changes: 5 additions & 11 deletions include/functional/fail.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,11 @@ namespace fn {
template <typename Fn, typename V>
concept invocable_fail //
= (some_expected_non_void<V> && requires(Fn &&fn, V &&v) {
{
::fn::invoke(FWD(fn), FWD(v).value())
} -> std::convertible_to<typename std::remove_cvref_t<V>::error_type>;
{ ::fn::invoke(FWD(fn), FWD(v).value()) } -> std::convertible_to<typename std::remove_cvref_t<V>::error_type>;
}) || (some_expected_void<V> && requires(Fn &&fn) {
{
::fn::invoke(FWD(fn))
} -> std::convertible_to<typename std::remove_cvref_t<V>::error_type>;
{ ::fn::invoke(FWD(fn)) } -> std::convertible_to<typename std::remove_cvref_t<V>::error_type>;
}) || (some_optional<V> && requires(Fn &&fn, V &&v) {
{
::fn::invoke(FWD(fn), FWD(v).value())
} -> std::same_as<void>;
{ ::fn::invoke(FWD(fn), FWD(v).value()) } -> std::same_as<void>;
});

constexpr inline struct fail_t final {
Expand Down Expand Up @@ -61,8 +55,8 @@ struct fail_t::apply final {
return type{std::unexpect, FWD(v).error()};
}

[[nodiscard]] static constexpr auto operator()(some_optional auto &&v, auto &&fn) noexcept
-> same_monadic_type_as<decltype(v)> auto
[[nodiscard]] static constexpr auto operator()(some_optional auto &&v,
auto &&fn) noexcept -> same_monadic_type_as<decltype(v)> auto
requires invocable_fail<decltype(fn), decltype(v)>
{
using type = std::remove_cvref_t<decltype(v)>;
Expand Down
28 changes: 10 additions & 18 deletions include/functional/filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,15 @@ namespace fn {
template <typename Pred, typename Err, typename V>
concept invocable_filter //
= (some_expected_non_void<V> && requires(Pred &&pred, Err &&on_err, V &&v) {
{
::fn::invoke(FWD(pred), std::as_const(v).value())
} -> convertible_to_bool;
{ ::fn::invoke(FWD(pred), std::as_const(v).value()) } -> convertible_to_bool;
{
::fn::invoke(FWD(on_err), FWD(v).value())
} -> std::convertible_to<typename std::remove_cvref_t<V>::error_type>;
}) || (some_expected_void<V> && requires(Pred &&pred, Err &&on_err, V &&v) {
{
::fn::invoke(FWD(pred))
} -> convertible_to_bool;
{
::fn::invoke(FWD(on_err))
} -> std::convertible_to<typename std::remove_cvref_t<V>::error_type>;
{ ::fn::invoke(FWD(pred)) } -> convertible_to_bool;
{ ::fn::invoke(FWD(on_err)) } -> std::convertible_to<typename std::remove_cvref_t<V>::error_type>;
}) || (some_optional<V> && std::same_as<Err, void> && requires(Pred &&pred, V &&v) {
{
::fn::invoke(FWD(pred), std::as_const(v).value())
} -> convertible_to_bool;
{ ::fn::invoke(FWD(pred), std::as_const(v).value()) } -> convertible_to_bool;
});

constexpr inline struct filter_t final {
Expand All @@ -48,8 +40,8 @@ constexpr inline struct filter_t final {
} filter = {};

struct filter_t::apply final {
[[nodiscard]] static constexpr auto operator()(some_expected_non_void auto &&v, auto &&pred, auto &&on_err) noexcept
-> same_monadic_type_as<decltype(v)> auto
[[nodiscard]] static constexpr auto operator()(some_expected_non_void auto &&v, auto &&pred,
auto &&on_err) noexcept -> same_monadic_type_as<decltype(v)> auto
requires invocable_filter<decltype(pred), decltype(on_err), decltype(v)>
{
using type = std::remove_cvref_t<decltype(v)>;
Expand All @@ -61,8 +53,8 @@ struct filter_t::apply final {
return FWD(v);
}

[[nodiscard]] static constexpr auto operator()(some_expected_void auto &&v, auto &&pred, auto &&on_err) noexcept
-> same_monadic_type_as<decltype(v)> auto
[[nodiscard]] static constexpr auto operator()(some_expected_void auto &&v, auto &&pred,
auto &&on_err) noexcept -> same_monadic_type_as<decltype(v)> auto
requires invocable_filter<decltype(pred), decltype(on_err), decltype(v)>
{
using type = std::remove_cvref_t<decltype(v)>;
Expand All @@ -74,8 +66,8 @@ struct filter_t::apply final {
return FWD(v);
}

[[nodiscard]] static constexpr auto operator()(some_optional auto &&v, auto &&pred) noexcept
-> same_monadic_type_as<decltype(v)> auto
[[nodiscard]] static constexpr auto operator()(some_optional auto &&v,
auto &&pred) noexcept -> same_monadic_type_as<decltype(v)> auto
requires invocable_filter<decltype(pred), void, decltype(v)>
{
using type = std::remove_cvref_t<decltype(v)>;
Expand Down
4 changes: 2 additions & 2 deletions include/functional/functional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ constexpr inline bool is_nothrow_invocable_r_v = is_nothrow_invocable_r<Ret, Fn,
// invoke
template <typename Fn, typename... Args>
requires is_invocable_v<Fn, Args...>
constexpr inline auto invoke(Fn &&fn, Args &&...args) noexcept(is_nothrow_invocable_v<Fn, Args...>)
-> invoke_result_t<Fn, Args...>
constexpr inline auto
invoke(Fn &&fn, Args &&...args) noexcept(is_nothrow_invocable_v<Fn, Args...>) -> invoke_result_t<Fn, Args...>
{
return detail::_invoke(FWD(fn), FWD(args)...);
}
Expand Down
16 changes: 4 additions & 12 deletions include/functional/inspect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,13 @@ namespace fn {
template <typename Fn, typename V>
concept invocable_inspect //
= (some_expected_non_void<V> && requires(Fn &&fn, V &&v) {
{
::fn::invoke(FWD(fn), std::as_const(v).value())
} -> std::same_as<void>;
{ ::fn::invoke(FWD(fn), std::as_const(v).value()) } -> std::same_as<void>;
}) || (some_expected_void<V> && requires(Fn &&fn) {
{
::fn::invoke(FWD(fn))
} -> std::same_as<void>;
{ ::fn::invoke(FWD(fn)) } -> std::same_as<void>;
}) || (some_optional<V> && requires(Fn &&fn, V &&v) {
{
::fn::invoke(FWD(fn), std::as_const(v).value())
} -> std::same_as<void>;
{ ::fn::invoke(FWD(fn), std::as_const(v).value()) } -> std::same_as<void>;
}) || (some_choice<V> && requires(Fn &&fn, V &&v) {
{
::fn::invoke(FWD(fn), std::as_const(v).value())
} -> std::same_as<void>;
{ ::fn::invoke(FWD(fn), std::as_const(v).value()) } -> std::same_as<void>;
});

constexpr inline struct inspect_t final {
Expand Down
8 changes: 2 additions & 6 deletions include/functional/inspect_error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@ namespace fn {
template <typename Fn, typename V>
concept invocable_inspect_error //
= (some_expected<V> && requires(Fn &&fn, V &&v) {
{
::fn::invoke(FWD(fn), std::as_const(v).error())
} -> std::same_as<void>;
{ ::fn::invoke(FWD(fn), std::as_const(v).error()) } -> std::same_as<void>;
}) || (some_optional<V> && requires(Fn &&fn) {
{
::fn::invoke(FWD(fn))
} -> std::same_as<void>;
{ ::fn::invoke(FWD(fn)) } -> std::same_as<void>;
});

constexpr inline struct inspect_error_t final {
Expand Down
Loading