lundi 17 septembre 2018

C++ Templates: Type to check validation

template <
    typename input_currency_type, typename output_currency_type,
    typename validation = convert_debug_policies::fast_validity_currency_type<input_currency_type>
>

fast_validity_currency_type<typename> represents a number of static_assertions, based on the given typename (recognized with template specialization).

Note: convert_debug_policies is a namespace.

This code compiles. However, I wondered whether typename validation is considered OK or slightly awkward. I can imagine it being awkward because the type is actually only used for the static assertions; it is not used except for during the assignment. It would perhaps seem to be preferable to keep typename validation nameless, but I actually want to use this so that the programmer does actually know exactly what it is; especially if another debug policy (in the namespace) is given.

So my question is, is this a good way to check the validation or should I use another way to validate?

I hope I'm not too vague - Feel free to ask if I need to elaborate. Thanks!

Aucun commentaire:

Enregistrer un commentaire