I was wondering if anyone knows a way of creating repetitive type declarations, and since this might be confusing an example will be helpful:
For our project we need to have function and type declarations like:
using FunType = std::function<void(double,double,double,double,double,double,double,double)>;
using DataType = std::tuple<double,double,double,double,double,double,double,double>;
scattered around several files, multiple times, up to 32 doubles (only doubles, if this is important).
I would be happy to replace the manual writing/counting of those doubles, with something in the lines of the following imaginary code:
using FunType = something_generate_function_decl<8>;
using DataType = something_generate_datatype_decl<8>
If possible I would like to stay away from boost and its preprocessor library.
Edit to provide some clarification
The big picture is that at some point in the application we get in a series of bytes (representing an array of doubles) with each value having a predefined meaning, we need to do validation on them (each value needs to be verified with several conditions for validity), reject data that is not valid, log the corresponding invalid data with its meaning, pass the meaningful data around the application, from logger module to a dozen of different places including existing functions and also Qt signals with already defined syntax etc... and at some point this will go out from our hands, so that's why I would like to create code as easily readable and verifiable as possible.
Edit2 to provide more clarification
Reading the comments, seemingly there is a lot of confusion about the scope of this question. There is intentionally a lot of information missing from the question which is not relevant to the pure essence of the question which is how to shorten those 8 (or 9, or 12, or 32 doubles) into a more manageable entity. The missing information is our internal way of dealing with the data we receive (we have a project of a large scale, so you can imagine that there are a few layers of abstraction for the data which does automatic validation, conversion, etc... before sending over, so not the entire application is a long list of if/else statements and basic function calls with parameters), the only restriction for the entire thing is that what comes in as a simple array of doubles (representing a message) is validated and then sent over to functions/QT signals/C++11 lambdas which already have a predefined interface. All the information handling and validation is encapsulated into layers of classes which just register themselves somewhere (out of scope for this question) for receiving, storing, validating and sending data, and for example, the FunType
(which actually is an internally used type of the message classes) represents the interface of the functions/slots/lambdas where the specific message (with its validated members) will be sent, automatically by some mechanism which gathers all the members into a tuple (DataType
) and the using some index_sequence
magic with variadic templates the compiler matches the tuple to the required function which at some point in time "subscribed" to this message.
@admin if you feel this edit not being relevant, feel free to delete it.