C++ std::apply made usable

std::apply is a typical example of those numerous standard C++ std lib types begging to be made comfortable.  Not just usable.

In it’s raw form it requires a lot of typing . So, I made one little wrapper that is really simple but makes std::apply much more palatable.

First let me show you the API.

Philosophy is: you first make specific “applicator” from a specific Callable object. Then you use it, wherever you need it.  To each API example bellow, I have added std::apply raw usage, on the line bellow.

(the summa() is here)

Not a big deal. Shorter but just slightly shorter. Ok, how about using tuples, as primary and only argument type to be passed (by design ) to std::apply. Here is the difference.

That’s a big difference in ease of usage.

And then there are types that my API can do, that std::apply can not do.

Initializer list’s , std::apply simply does not let you use. And what about native arrays?

I know std::array is rather nice, and I use it too whenever I can, but in real life code, native arrays no one can avoid to use. An ocean of them native arrays.  Instead of writing your own transformations, feel free to use my API.

There is more examples.  What about F( a, b,  F(c, d)) situation? Function result used as one of the arguments to the same function.

Now at least one can attempt this kind of computations with the help of my API.

The Free Code

Is rather simple  and lovingly short.

This is C++17.  Enjoy it.

So little C++ so much good!
So little C++ so much good!

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.