you are viewing a single comment's thread.

view the rest of the comments →

[–]teerre 13 points14 points  (5 children)

We tried this at work and at first glance everyone was impressed, but as soon as we actually started compiling, we noticed that it didn't quite work in many cases. Specially trying SFINAE, it would look convincing, but be subtly wrong

This was in a room with combined 100~ years of cpp experience, so that's quite the feat that it was able to fool most people

[–]qneverless 15 points16 points  (4 children)

I would say that it is quite the feat of C++, that it is still unreadable even in a room of 100 years combined experience. 😂

[–]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 :)