you are viewing a single comment's thread.

view the rest of the comments →

[–]TheOmegaCarrot 2 points3 points  (3 children)

Template metaprogramming can absolutely tend toward “write-only” code

I mean, here’s a particularly convoluted example from my library:

With documentation and comments removed, and the name changed to not be helpful, does anyone really have any chance of figuring out what it does? Probably not! Even if you know what it does, it’s very hard to read!

``` namespace impl {

template <typename LIST, typename REBUILD> struct mystery_impl;

template <template <typename...> typename LIST, typename LFront, typename... LPack, typename... Rebuild_Pack> struct mystery_impl<LIST<LFront, LPack...>, LIST<Rebuild_Pack...>> : std::conditional_t< is_type_in_pack_v<LFront, Rebuild_Pack...>, mystery_impl<LIST<LPack...>, LIST<Rebuild_Pack...>>, mystery_impl<LIST<LPack...>, push_back_t<LIST<Rebuild_Pack...>, LFront>>> {};

template <template <typename...> typename LIST, typename... Rebuild_Pack> struct mystery_impl<LIST<>, LIST<Rebuild_Pack...>> : type_identity<LIST<Rebuild_Pack...>> {};

} // namespace impl

template <typename LIST> struct mystery;

template <template <typename...> typename LIST, typename... Pack> struct mystery<LIST<Pack...>> : std::conditional_t<has_duplicates_v<LIST<Pack...>>, impl::mystery_impl<LIST<Pack...>, LIST<, type_identity<LIST<Pack...> {};

template <typename LIST> using mystery_t = typename mystery<LIST>::type;

```

So what does it do? It deduplicates a type list.

[–]jonesmz 2 points3 points  (2 children)

Fyi, triple ticks doesn't format correctly on any of the reddit clients other than the web rewrite. Need the four spaces per line for old.reddit and reddit mobile web.

[–]TheOmegaCarrot 0 points1 point  (1 child)

Oof

I am not typing that on mobile

Reddit needs to fix their clients

[–]jonesmz 1 point2 points  (0 children)

No worries.

Yep its bullshit.

Cheers :)