← Back to context

Comment by a_t48

3 days ago

Oh man, some of the code in the linked proposal:

Old:

    template<class...> struct list {};

    using types = list<int, float, double>;

    constexpr auto sizes = []<template<class...> class L, class... T>(L<T...>) {
      return std::array<std::size_t, sizeof...(T)>{{ sizeof(T)... }};
    }(types{});

New:

    constexpr std::array types = {^^int, ^^float, ^^double};
    constexpr std::array sizes = []{
      std::array<std::size_t, types.size()> r;
      std::ranges::transform(types, r.begin(), std::meta::size_of);
      return r;
    }();

I'm so tired of parameter packs, as useful as they are. Just give me a regular range based for loop or something similar like this. Thank you, this can't come soon enough.

This is when I switch to a programming language that doesn't block me from compiling and running just because I forgot some intricate detail. Ironically, I often find assembly programming much friendly.

BTW, I continue to maintain some C++ software, and I like cryptopp [1]. I know people now use libsodium.

[1] https://github.com/weidai11/cryptopp

  • I continue to maintain robotics software that nobody uses, such is life. :)

But the standard library should have had things so that we can write:

    constexpr std::array types = {^^int, ^^float, ^^double};
    auto sizes = std::whatever::transform(types, std::meta::size_of);

which would have been even nicer.

  • It would have been, but it looks like the difficulty there is that the type of `sizes` must be compile time known, but `std::transform` and friends don't really know about fixed sizes. Depending on the context, one can do `auto sizes = types | std::views::transform(std::meta::size_of);`, the difficulty comes in materializing at the end.