C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Where standard library for working with packs?

From: Jonathan Wakely <cxx_at_[hidden]>
Date: Sat, 12 Aug 2023 12:48:20 +0100
On Sat, 12 Aug 2023, 12:18 Nikl Kelbon via Std-Proposals, <
std-proposals_at_[hidden]> wrote:

> A huge amount of code, extremely complex and slowing down compilation
> speed, is written to do simple things.
> Typical examples: searching in a pack by index, checking that pack
> contains type, checking that all elements in the pack are unique
>
> Seemingly strange and inapplicable things in practice, such as sorting
> types in a pack, can actually be incredibly useful
> Example:
> there is a std::variant, but i want
> * always get by type, since this is logical, and repeating types in a
> variant are either an error or extremely strange code
> * variant<int, double> must be equal to variant<double, int> because I
> want to generate fewer types / code
>
> But I can't write
>
> using namespace std::types;
> template<typename... Ts>
> using my_variant = decltype(pack<Ts...> | sort | remove_duplicates |
> insert<std::variant>);
>
> ***
>
> Another example: I want a memory-efficient tuple. For this I want to sort
> the types by size(alligment...)
>
> ---
>
> I could implement this in a separate library, BUT
> 1. No one will connect the library for the sake of this, everyone will
> write their own curves and bicycles incomprehensible to the reader for
> thousands of lines
> 2. Any implementation outside the standard library would be very
> inefficient, while the standard would allow compilers to make intrinsics.
>
> So i propose a stl-algorithms std::ranges like standard library part,
> which will consists of such basic primitives like find, sort, reverse,
> unique for types
>

There is
https://www.boost.org/doc/libs/1_83_0/libs/mp11/doc/html/simple_cxx11_metaprogramming.html
and Eric Niebler's meta library.

Somebody could turn mp11 into a proposal.

Received on 2023-08-12 11:48:36