1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
Erasing all types tt(EraseType) from a tt(TypeList) can easily be accomplished
by applying the erasure procedure not only to the head of the tt(TypeList) but
also to the tt(TypeList)'s tail.
Here is the algorithm, described in a slightly different order than
tt(Erase)'s algorithm:
itemization(
it() If the tt(TypeList) is empty, there's nothing to erase, and an empty
tt(TypeList) results. This is exactly what we do with tt(Erase), so we
can use inheritance to prevent us from having to duplicate elements of
a template meta program:
verbinclude(//ERASEIDXEMPTY examples/erase.h)
it() The foundation of the algorithm is therefore a struct template
tt(EraseAll) expecting the type to erase and a tt(TypeList) that is
derived from tt(Erase), thus already offering the empty tt(TypeList)
handling specialization:
verbinclude(//ERASEALL examples/erase.h)
it() If tt(TypeList)'s head matches tt(EraseType) tt(EraseAll) is also
applied to the tt(TypeList)'s tail, thus removing all occurrences of
tt(EraseType) from tt(TypeList):
verbinclude(//ERASEALLTYPES examples/erase.h)
it() In all other cases (i.e., tt(TypeList)'s head does em(not) match
tt(EraseType)) tt(EraseAll) is applied to the tt(TypeList)'s tail.
The returned tt(TypeList) consists of the original tt(TypeList)'s
initial type and the types of the tt(TypeList) returned by the
recursive tt(EraseAll) call:
verbinclude(//ERASEALLNEXT examples/erase.h)
)
Here is a statement showing how tt(EraseAll) can be used:
verbinclude(//ERASEALL examples/erase.cc)
|