C++ std::apply made usable

So little C++ so much good!

The Free Code


The code is rather simple and lovingly short. C++17 or 20. I am not building console apps so first my primitive logging.

C++ is made to be used in systems programming, aka “the server-side” aka “unattended”, thus I do not use console apps. That logging above is not part of std::apply but here it is, for the sampling code to be used. Now “the core of the trick”.


summator now exhibits few call operator overloads, you can see in the code above.  The argument is first transformed to tuple like std type and then passed to the apply call on the callable object given at construction time. For example in the case of a native array, it is transformed into the std array, which is “tuple like” type.

In my own tradition, I am not adding any type traits mumbo jumbo compile-time checks. If you use as ‘Callable above something that is not, the compiler will simply not let you use it.

Similarly, if you use the fact all return values are constexpr go for it. C++20 certainly opens the door for compile-time computing wider.

I think this utility is amazingly simple and improves the quality and readability of the code using std::apply considerably. Enjoy.


The summa` used to explain the API above. The function we will use as the “callable” specimen to which we will “apply” all kinds of arguments. (But of the same type.)

Of course, all the args above have to be of the same type. They are being simply added together. Hence that static_assert in there. That is almost easy to code. I am sure you will manage without my explanation.