C++ Functional procedure in elements of programming

Viewed 71

I am reading the Elements of Programming by Stepanov & Jones, implementing things as I go using concepts from c++20. Early on, the authors define functional procedures:

A functional procedure is a regular procedure defined on regular types, with one or more direct inputs and a single output that is returned as the result of the procedure

In their code samples, they use it like so:

 template<typename T>
     requires(FunctionalProcedure(T))
 struct codomain_type; 

But nowhere is FunctionalProcedure defined (I could not find it anyway). The thing I find interesting is that in their implementation, they use a simple template parameter (T in the code above) to capture the procedure. Is such a thing possible using regular c++?

For example, in my code, I am using

template <typename Op, typename... Args>
concept FunctionalProcedure = std::regular_invocable<Op, Args...>;

But then, I keep carrying the parameter pack Args in every single concept / metafunction I create. Most type traits / concepts from the standard require both the callable and its arguments, but I don't think it's possible to get that info from the lambda type (or functor for that matter). I can only do that easily if I stick with std::function.

Is there a way around this issue? Are they able to do this in the book because they use a modified, simpler version of c++?

0 Answers
Related