atx crypto club

programminchatter

#programminchatter

Anon Ymous

Sat Aug 10 04:25:55 2024
(*097dfbf6*):: been getting into the weeds again with c++ for something I’m working on for the day job. It’s amazing how the new iterations of C++ walks the thin line between God tier elegance and incomprehensible and useless academic wankery nonsense

template
void f(Ts&&... args)
{
auto myLambda = [...args = std::forward(args)](){};
}

Here’s an example of lambda capture of a variadic pack of parameters. It’s actually a badass feature. Template lambdas were cleaned up from C++14 which used awkward auto&& for variable types (which I still have to use now because we’re stuck on gcc 8.x for this project) and this lets you capture a templated variable list of arguments then pass the lambda around like any other variable. I can’t wrap my head around how they got this to work in the compiler. The auto keyword started out as a nice to have, letting the compiler deduce the type based on the right side of the assignment operator, and now it is impossible to go without for modern lambdas and other stuff. The underlying type declaration is probably retarded. I can’t even think of how to express it haha. In a dynamic language like python this kind of stuff is easy but slow. It’s really cool IMO but I know C++ h8rs would probably throw up all over their keyboard trying to mentally parse modern C++. Even for people that happily use C++ everyday for their jobs- if I actually used this in production code my team would be like wtf is this BS? this compiles??? lmao

Now thats really nothing, if you want to get really retarded you can do functional programming using the arcane knowledge of C++ template metaprogramming. I’ve never run into this in the wild except for some specialized, limited cases but psychopaths are writing elaborate software that runs at compile time! Stuff like abusing the type system where you have thousands of nested types to compute something before any actual runtime executes. Pure unmitigated madness :cool-doge: https://blog.nelhage.com/post/advent-of-templates/
*** Advent of Code in C++ Template Metaprogramming
*** Implementing Advent of Code in C++ … via compile-time template metaprogramming
*** Made of Bugs
(*097dfbf6*):: +public!

Back to top