Changeset 5d3a952 for doc/theses/aaron_moss_PhD/phd/generic-types.tex
- Timestamp:
- Apr 24, 2019, 9:31:21 PM (3 years ago)
- Branches:
- aaron-thesis, arm-eh, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr
- Children:
- 69c37cc
- Parents:
- 39de1c5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/aaron_moss_PhD/phd/generic-types.tex
r39de1c5 r5d3a952 27 27 int int_list_head( const struct int_list* ls ) { return ls->value; } 28 28 29 $\C[\textwidth]{// all code must be duplicated for every generic instantiation}$29 // all code must be duplicated for every generic instantiation 30 30 31 31 struct string_list { const char* value; struct string_list* next; }; … … 40 40 { return ls->value; } 41 41 42 $\C[\textwidth]{// use is efficient and idiomatic}$42 // use is efficient and idiomatic 43 43 44 44 int main() { … … 65 65 struct list { void* value; struct list* next; }; 66 66 67 $\C[\textwidth]{// internal memory management requires helper functions}$67 // internal memory management requires helper functions 68 68 69 69 void list_insert( struct list** ls, void* x, void* (*copy)(void*) ) { … … 75 75 void* list_head( const struct list* ls ) { return ls->value; } 76 76 77 $\C[\textwidth]{// helpers duplicated per type}$77 // helpers duplicated per type 78 78 79 79 void* int_copy(void* x) { … … 105 105 #include <stdio.h> $\C{// for printf}$ 106 106 107 $\C[\textwidth]{// code is nested in macros}$107 // code is nested in macros 108 108 109 109 #define list(N) N ## _list … … 127 127 define_list(string, const char*); $\C[3in]{// defines string\_list}$ 128 128 129 $\C[\textwidth]{// use is efficient, but syntactically idiosyncratic}$129 // use is efficient, but syntactically idiosyncratic 130 130 131 131 int main() { … … 156 156 forall(otype T) struct list { T value; list(T)* next; }; 157 157 158 $\C[\textwidth]{// single polymorphic implementation of each function}$159 $\C[\textwidth]{// overloading reduces need for namespace prefixes}$158 // single polymorphic implementation of each function 159 // overloading reduces need for namespace prefixes 160 160 161 161 forall(otype T) void insert( list(T)** ls, T x ) { … … 167 167 forall(otype T) T head( const list(T)* ls ) { return ls->value; } 168 168 169 $\C[\textwidth]{// use is clear and efficient}$169 // use is clear and efficient 170 170 171 171 int main() {
Note: See TracChangeset
for help on using the changeset viewer.