|
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.
|
Validation utilities for tuple-like traits, comprising structural detection of tuple-like semantics and strict matching for pair-like binary tuple structures. More...
Go to the source code of this file.
Namespaces | |
| namespace | jh::concepts |
| Behavioral concept namespace of the JH Toolkit. | |
Concepts | |
| concept | jh::concepts::tuple_like |
| Concept recognizing tuple-like types. | |
| concept | jh::concepts::pair_like_for |
Checks whether a type P is a 2-element tuple-like whose element types exactly match K and V (after remove_cvref). | |
Validation utilities for tuple-like traits, comprising structural detection of tuple-like semantics and strict matching for pair-like binary tuple structures.
This header provides compile-time mechanisms that verify whether a type fulfills the requirements of the tuple-like protocol used by the C++ standard, particularly those governing structured bindings. These mechanisms do not introduce tuple-like behavior but instead validate user-defined or library-defined types that claim to conform to the protocol.
The jh::concepts::tuple_like concept performs structural verification of tuple-like semantics. A type is considered tuple-like when the following conditions are satisfied:
std::tuple_size<T> specialization exists. get<I>(t) is available through argument-dependent lookup for each valid index. get forms a valid
std::common_reference_t with the corresponding std::tuple_element<I, T>::type. These rules correspond to the semantics used by structured bindings. They also allow proxy-based tuple-like types whose element references differ from the declared tuple_element types as long as their common reference relationships represent compatible semantics.
The jh::concepts::pair_like_for concept is a derived, more restrictive form of tuple-like validation. Inspired by proposals in Clang regarding the use of binary tuple-like structures as inputs to associative container interfaces, it verifies that:
Unlike tuple_like, which only checks semantic compatibility, pair_like_for enforces strict equality of canonical element types. This ensures the type behaves as a pair-like entity in a strong and predictable manner.
1.3.x
2025