Ho due struct:const-ness come argomento di un template
// ----- non-const -----
struct arg_adapter
{
EArgType type; // fmtA, fmtB, ...
union
{
TypeA * valueA;
TypeB * valueB;
// ... more types
}
arg_adapter(TypeA & value) : type(fmtA), valueA(&value) {}
arg_adapter(TypeB & value) : type(fmtB), valueB(&value) {}
// ...
}
// ----- const version -----
struct const_arg_adapter
{
EArgType type; // fmtA, fmtB, ...
union
{
TypeA const * valueA;
TypeB const * valueB;
// ... more types
}
arg_adapter(TypeA const & value) : type(fmtA), valueA(&value) {}
arg_adapter(TypeB const & value) : type(fmtB), valueB(&value) {}
// ...
}
che sono chiamati a essere usato in metodi come ad esempio:
Convert(const_arg_adapter from, arg_adapter to)
ci sono TypeX multipla'(circa 5, può diventare più), molti dei quali primitivi. Questo per evitare di mantenere diversi prototipi.
Ora la mia domanda ;-)
C'è un modo per rendere il const-ness un parametro di modello? Il mio obiettivo è quello di mantenere una sola struct, cioè
template <Qualifier CONSTNESS>
struct arg_adapter_t
{
...
CONSTNESS TypeA * valueA;
...
}
Forse aggiungere qualche 'typedef' eviterebbe di ripetere' typename applicare :: type' troppo :) –
@Matthieu in C++ 0x, potremmo semplicemente dire "applica &'. Adoro gli alias del modello :) –
così farò anch'io, così farò :) Sto aspettando con impazienza modelli di alias e template variadici, mi chiedo solo quale compilatore lo farà per primo:/ –