Skip to content

Commit bcbb31f

Browse files
committed
Do actual template specialization
1 parent 33a5c8c commit bcbb31f

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

include/cleanup.h

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,34 @@
33

44
#include <SDL.h>
55

6+
/*
7+
* Clean up each argument in the list
8+
*/
9+
template<typename T, typename... Args>
10+
void cleanup(T *t, Args&&... args){
11+
cleanup(t);
12+
cleanup(std::forward<Args>(args)...);
13+
}
614
/*
715
* These serve to free the passed argument and also provide the
816
* base cases for the template recursion
917
*/
10-
void cleanup(SDL_Window *win){
18+
template<>
19+
void cleanup<SDL_Window>(SDL_Window *win){
1120
SDL_DestroyWindow(win);
1221
}
13-
void cleanup(SDL_Renderer *ren){
22+
template<>
23+
void cleanup<SDL_Renderer>(SDL_Renderer *ren){
1424
SDL_DestroyRenderer(ren);
1525
}
16-
void cleanup(SDL_Texture *tex){
26+
template<>
27+
void cleanup<SDL_Texture>(SDL_Texture *tex){
1728
SDL_DestroyTexture(tex);
1829
}
19-
void cleanup(SDL_Surface *surf){
30+
template<>
31+
void cleanup<SDL_Surface>(SDL_Surface *surf){
2032
SDL_FreeSurface(surf);
2133
}
22-
/*
23-
* Clean up each argument in the list
24-
*/
25-
template<typename T, typename... Args>
26-
void cleanup(T *t, Args&&... args){
27-
cleanup(t);
28-
cleanup(std::forward<Args>(args)...);
29-
}
3034

3135
#endif
3236

0 commit comments

Comments
 (0)