- Timestamp:
- Apr 16, 2017, 10:42:15 AM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 19b2133
- Parents:
- 0aad606
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/generic_types/generic_types.tex
r0aad606 r10e0fcd 823 823 struct S { int x, y; }; 824 824 forall(otype T, ttype Params | { void print(T); void print(Params); }) void print(T arg, Params rest) { 825 print(arg); 826 print(rest); 825 print(arg); print(rest); 827 826 } 828 827 void print( char * x ) { printf( "%s", x ); } … … 839 838 For example, it is possible to write @new@ as a library function: 840 839 \begin{lstlisting} 841 struct pair( otype R, otype S ); 842 forall( otype R, otype S ) void ?{}( pair(R, S) *, R, S ); // (1) 840 forall( otype R, otype S ) void ?{}( pair(R, S) *, R, S ); 843 841 forall( dtype T, ttype Params | sized(T) | { void ?{}( T *, Params ); } ) T * new( Params p ) { 844 return ((T *)malloc( sizeof(T) )){ p }; // construct into result of malloc842 return ((T *)malloc()){ p }; $\C{// construct into result of malloc}$ 845 843 } 846 844 pair( int, char ) * x = new( 42, '!' );
Note: See TracChangeset
for help on using the changeset viewer.