Creating a pipe that can morph types within without experimental::any

I am trying to create a pipe implementation that would expose an interface to chain multiple manipulations on some given data while maintaining immutability of the said data. The caveat here is that the manipulations (which are, obviously, just pure functions) should be able to morph the type of the data (e. g. a pipe that is created from an OpenCV mat that should pass through an OCR tool, which would result in a string output). That said, I made this implementation which utilizes std::experimental::any.

Well, it works. The problem is that it is error-prone, since you have to use explicit

any_cast

any time you want to actually access the data concealed by

any

. That said, any reducer function has to guess what type it will receive, and if that doesn't match the reality, that's a runtime error, i.e. a lot of unnecessary try-catches or something in the code, as well as those additional lines for explicit typecasting.