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
container_traits.h File Reference

Unified deduction model for container element types. More...

#include <ranges>
#include <type_traits>
#include "jh/conceptual/iterator.h"
#include "jh/conceptual/sequence.h"

Go to the source code of this file.

Namespaces

namespace  jh::concepts
 Behavioral concept namespace of the JH Toolkit.

Concepts

concept  jh::concepts::is_contiguous_reallocable
 Concept that constrains types usable in contiguous, reallocating containers.

Typedefs

template<typename C>
using jh::concepts::container_value_t = typename detail::container_value_type_impl<C>::type
 Deduce the value type of a container C.

Detailed Description

Unified deduction model for container element types.

Author
JeongHan-Bae <mastropseudo@gmail.com>

This header defines the trait jh::concepts::container_value_t, a unified and extensible mechanism for deducing the value type of arbitrary container-like types. It harmonizes three deduction strategies — user registration, declared value_type, and iterator-based inference — under a deterministic priority system.

Purpose

Many standard and custom containers expose different or ambiguous value-type information. This trait provides a canonical, conflict-resolving method to obtain a single consistent element type used across the entire jh::concepts subsystem (e.g. in closable_container_for and collectable_container_for).

Deduction priority

  1. User override: jh::container_deduction<C>::value_type — explicit registration always takes precedence.
  2. Declared type: C::value_type — used if no override is present.
  3. Iterator-based deduction: extracted via iterator_t<C> and iterator_value_t<iterator_t<C>>.
  4. Conflict resolution: if both declared and deduced forms exist and share a common reference, the declared form wins.
  5. Fallback: void — deduction failure.

User customization point

Custom containers can specialize jh::container_deduction<C> to explicitly define a value_type. This mechanism overrides all automatic deduction and provides a stable interface for third-party containers that do not follow standard iterator or value conventions.

Design rationale

  • Fully constexpr and SFINAE-safe; compatible with incomplete types.
  • Consistent with std::ranges conventions while allowing user extension without ADL or traits injection.
  • Provides uniform type deduction across collect, to, and all range-concept meta-utilities.
See also
jh::concepts::iterator_t
jh::concepts::sequence_t
jh::concepts::closable_container_for
jh::concepts::collectable_container_for
Version
1.3.x
Date
2025