Changeset e6dceef
- Timestamp:
- Apr 11, 2017, 1:45:03 PM (8 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:
- 87c5f40
- Parents:
- 5a48d79
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/generic_types/generic_types.tex
r5a48d79 re6dceef 1 1 % take off review (for line numbers) and anonymous (for anonymization) on submission 2 % \documentclass[format=acmlarge, anonymous,review]{acmart}3 \documentclass[format=acmlarge,review]{acmart}2 \documentclass[format=acmlarge,anonymous,review]{acmart} 3 % \documentclass[format=acmlarge,review]{acmart} 4 4 5 5 \usepackage{xspace,calc,comment} … … 758 758 It is also possible to use @ttype@ polymorphism to provide arbitrary argument forwarding functions. For example, it is possible to write @new@ as a library function: 759 759 \begin{lstlisting} 760 struct Pair(otype R, otype S);760 struct pair(otype R, otype S); 761 761 forall(otype R, otype S) 762 void ?{}( Pair(R, S) *, R, S); // (1)762 void ?{}(pair(R, S) *, R, S); // (1) 763 763 764 764 forall(dtype T, ttype Params | sized(T) | { void ?{}(T *, Params); }) … … 767 767 } 768 768 769 Pair(int, char) * x = new(42, '!');769 pair(int, char) * x = new(42, '!'); 770 770 \end{lstlisting} 771 771 The @new@ function provides the combination of type-safe @malloc@ with a constructor call, so that it becomes impossible to forget to construct dynamically allocated objects. This function provides the type-safety of @new@ in \CC, without the need to specify the allocated type again, thanks to return-type inference. 772 772 773 In the call to @new@, @Pair(double, char)@ is selected to match @T@, and @Params@ is expanded to match @[double, char]@. The constructor (1) may be specialized to satisfy the assertion for a constructor with an interface compatible with @void ?{}(Pair(int, char) *, int, char)@. 774 775 \TODO{Check if we actually can use ttype parameters on generic types (if they set the complete flag, it should work, or nearly so).} 773 In the call to @new@, @pair(double, char)@ is selected to match @T@, and @Params@ is expanded to match @[double, char]@. The constructor (1) may be specialized to satisfy the assertion for a constructor with an interface compatible with @void ?{}(pair(int, char) *, int, char)@. 776 774 777 775 \subsection{Implementation}
Note: See TracChangeset
for help on using the changeset viewer.