|
JH-Toolkit v1.4.1
An engineering-oriented C++20 toolkit with duck-typed concepts, static design, async coroutines, and semantic containers — header-only, RTTI-free, and concurrency-friendly.
|
ADL-enabled universal tuple application utility — extends std::apply to arbitrary tuple-like structures, including user-defined proxies and view elements.
More...
#include "jh/conceptual/tuple_like.h"#include <functional>#include <tuple>#include <utility>#include <type_traits>Go to the source code of this file.
Namespaces | |
| namespace | jh::meta |
| Aggregated entry point for compile-time metaprogramming utilities. | |
Functions | |
| template<class F, class T, size_t... I> | |
| constexpr decltype(auto) | jh::meta::adl_apply_impl (F &&f, T &&t, std::index_sequence< I... >) |
Internal implementation helper for jh::meta::adl_apply. | |
| template<class F, jh::concepts::tuple_like T> | |
| constexpr decltype(auto) | jh::meta::adl_apply (F &&f, T &&t) noexcept(noexcept(adl_apply_impl(std::forward< F >(f), std::forward< T >(t), std::make_index_sequence< std::tuple_size_v< std::remove_cvref_t< T > > >{}))) |
| ADL-enabled universal apply for tuple-like objects. | |
ADL-enabled universal tuple application utility — extends std::apply to arbitrary tuple-like structures, including user-defined proxies and view elements.
The jh::meta::adl_apply function is a generalized alternative to std::apply that allows invocation of callables on both standard and user-defined tuple-like objects. It performs unqualified lookup for get to enable
Argument-Dependent Lookup (ADL), thereby extending support beyond the
standard tuple family.
The C++ standard restricts std::apply to built-in tuple-like types (std::tuple, std::pair, std::array), because std::apply directly calls std::get.
However:
get functions cannot reside in std namespace; std::get cannot be specialized for non-standard types; C++ nevertheless permits defining tuple_size and tuple_element for custom structures; Thus, a large class of tuple-like proxies (e.g., jh::ranges::zip_reference_view supporting jh::ranges::zip_view) as well as a lot of third-party defined tuple-like proxies cannot work with std::apply.
jh::meta::adl_apply bridges this semantic gap by employing unqualified get calls, so both standard and ADL-visible
overloads participate in lookup. It effectively becomes a
universal apply for all tuple-like types.
std::tuple, std::pair, std::array. jh::concepts::tuple_like (i.e., define tuple_size / tuple_element and expose ADL-visible get).
Proxy-based ranges: view elements such as
jh::ranges::zip_reference_view.
get — enabling ADL discovery.
Expands index sequence from std::tuple_size_v<T>. Perfect-forwards both callable and tuple object.
Propagates noexcept and constexpr guarantees.
In this example, enumerate() yields a tuple-like proxy containing an index and reference. collect internally employs jh::meta::adl_apply to unpack the proxy into actual std::pair<size_t, std::string> values via emplace_back().
std::get. get functions.
Compile-time safety: constrained by jh::concepts::tuple_like. Zero-overhead abstraction: identical assembly as std::apply for STL tuples. 1.3.x
2025