From 652785f8fc5e312fbb5e5d29c3ac55ace1d9b327 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 15 Nov 2022 23:57:47 +0100 Subject: put all 'namespace detail' stuff in one place --- src/entity.hpp | 56 ++++++++++++++++++++++++++------------------------------ 1 file changed, 26 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/entity.hpp b/src/entity.hpp index 44f6295a..50b8a4d0 100644 --- a/src/entity.hpp +++ b/src/entity.hpp @@ -121,6 +121,32 @@ constexpr inline std::size_t strlen_(const char* s) #endif } +template +requires std::invocable(std::declval()))> +constexpr CORRADE_ALWAYS_INLINE void visit_tuple(F&& fun, Tuple&& tuple) +{ + using Size = std::tuple_size>; + static_assert(N < Size()); + + fun(std::get(tuple)); + if constexpr(N+1 < Size()) + visit_tuple(std::forward(fun), std::forward(tuple)); +} + +template +requires std::is_invocable_r_v(std::declval()))> +constexpr CORRADE_ALWAYS_INLINE bool find_in_tuple(F&& fun, Tuple&& tuple) +{ + using Size = std::tuple_size>; + static_assert(N < Size()); + + if (fun(std::get(tuple))) + return true; + if constexpr(N+1 < Size()) + return find_in_tuple(std::forward(fun), std::forward(tuple)); + return false; +} + } // namespace detail struct EntityBase {}; @@ -162,36 +188,6 @@ struct Entity final : EntityBase { }; }; -namespace detail { - -template -requires std::invocable(std::declval()))> -constexpr CORRADE_ALWAYS_INLINE void visit_tuple(F&& fun, Tuple&& tuple) -{ - using Size = std::tuple_size>; - static_assert(N < Size()); - - fun(std::get(tuple)); - if constexpr(N+1 < Size()) - visit_tuple(std::forward(fun), std::forward(tuple)); -} - -template -requires std::is_invocable_r_v(std::declval()))> -constexpr CORRADE_ALWAYS_INLINE bool find_in_tuple(F&& fun, Tuple&& tuple) -{ - using Size = std::tuple_size>; - static_assert(N < Size()); - - if (fun(std::get(tuple))) - return true; - if constexpr(N+1 < Size()) - return find_in_tuple(std::forward(fun), std::forward(tuple)); - return false; -} - -} // namespace detail - template constexpr void visit_tuple(F&& fun, Tuple&& tuple) { -- cgit v1.2.3