Document: P3971R0
Author: Daniel Towner (Intel)
Date: 2026-02-20
Audience: LEWG
Proposes std::rebind<NewT>(container) - a generalized facility for converting containers and other types to use a different element type while preserving structure. std::rebind<double>(std::array<float, 4>) yields std::array<double, 4>. Works uniformly across array, vector, complex, and user-defined types. Follows precedent from simd::rebind_t in P1928R15.
This fills a real gap. Converting
vector<float>tovector<double>uses range constructors. Convertingarray<float, N>toarray<double, N>requires manual element copying. Convertingcomplex<float>tocomplex<double>needs direct construction.std::rebind<double>(data)unifies all three. Generic code shouldn't need to know which container it's rebinding.The simd library already has
rebind_tfor changing element types. This generalizes that concept to the rest of the standard library. Good precedent to build on.We already have
std::allocator_traits<A>::rebind_alloc<U>for allocators. This is the same idea applied to containers. The naming is consistent. The concept is well-understood.How do user-defined types opt in? Is it a CPO, a specialization of a trait, or ADL? The design choice matters for extensibility. A trait specialization like
rebind_result<NewT, Container>would be most flexible.Daniel Towner from Intel also authored P3973R0 (
bit_cast_asfor simd). The simd team is systematically filling ergonomic gaps in the simd API and generalizing the useful patterns.