Re: type traits and element specific functions: design problem
Greg Herlihy wrote:
Andy wrote:
[...]
I tried the following approach:
Create a dialog_traits class template. For each dialog Id, specialize
it and define a typedef in the specializtion which refers to the type
of the validator appropriate for this dialog. Something like:
template <int DLG_ID> struct dialog_traits;
template <>
struct dialog_traits<Dialog_Which_File> // say Dialog_Which_File == 5
{
typedef FileNameInputValidator validator_t;
};
- This still creates a pretty large number of template classes - one
for each validator and the executable size can increase significantly
because of this.
What "code" could a typedef declaration be adding to a program?
The fact that the functions which use it will have to be
templates as well. Currently, he has a function along the lines
of:
void dialog( int dialogId ) ;
which is called:
dialog( someId ) ;
With this proposed solution, the first function will become a
template, and the call will become:
dialog< someId >() ;
Personally, I doubt that the code bloat would be that important,
but there will be some. A more telling argument, IMHO, is that
it requires a constant dialog id at the call site. The day he
wants to use some sort of script to sequence the dialogs (a
frequent solution when things become long or complicated), he'll
have to redesign it anyway, since he'll need to pass a variable.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]