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.
Loading...
Searching...
No Matches
flatten.h File Reference

View adaptor for flattening tuple-like elements in a range. More...

#include <ranges>
#include "jh/metax/flatten_proxy.h"
#include "jh/ranges/views/transform.h"

Go to the source code of this file.

Namespaces

namespace  jh::ranges
 Semantic pipeline namespace for JH range operations.
namespace  jh::ranges::views
 Range view adaptor implementations with explicit semantic control.

Variables

constexpr detail::flatten_fn jh::ranges::views::flatten {}
 User-facing flatten adaptor.

Detailed Description

View adaptor for flattening tuple-like elements in a range.

Author
JeongHan-Bae <mastropseudo@gmail.com>

The jh::ranges::views::flatten adaptor produces a lazy view that inspects each element of a range and, if it models jh::concepts::tuple_like, wraps it in a jh::meta::flatten_proxy. Non-tuple-like elements are forwarded unchanged.

Behavior

  • Tuple-like elements are recursively flattened into jh::meta::flatten_proxy objects.
  • Non-tuple-like elements are passed through as-is.
  • The transformation is applied lazily; no element is copied or expanded eagerly.

Implementation Notes

  • flatten delegates to jh::ranges::views::transform.
  • jh::ranges::views::transform internally decides whether to construct a non-consuming or consuming transformation view depending on the behavior of the projection function.
  • Because flatten is a pure observation, its output preserves the consumption property of the underlying range: if the input is non-consuming, the output remains non-consuming; if the input is single-pass, the result is also single-pass.
Version
1.3.x
Date
2025