|
| 1 | +# Module name: Passing Parameters by Reference |
| 2 | +_Skeleton descriptions are typeset in italic text,_ |
| 3 | +_so please don't remove these descriptions when editing the topic._ |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +_Provides a short natural language abstract of the module’s contents._ |
| 8 | +_Specifies the different levels of teaching._ |
| 9 | + |
| 10 | +<table> |
| 11 | + <thead> |
| 12 | + <th>Level</th> |
| 13 | + <th>Objectives</th> |
| 14 | + </thead> |
| 15 | + <tr> |
| 16 | + <td>Foundational</td> |
| 17 | + <td>Avoiding copies using const-reference modifiers</td> |
| 18 | + </tr> |
| 19 | + <tr> |
| 20 | + <td>Main</td> |
| 21 | + <td>Using references to modify external data</td> |
| 22 | + </tr> |
| 23 | + <tr> |
| 24 | + <td>Advanced</td> |
| 25 | + <td></td> |
| 26 | + </tr> |
| 27 | +</table> |
| 28 | + |
| 29 | +## Motivation |
| 30 | + |
| 31 | +_Why is this important?_ |
| 32 | +_Why do we want to learn/teach this topic?_ |
| 33 | + |
| 34 | +## Topic introduction |
| 35 | + |
| 36 | +_Very brief introduction to the topic._ |
| 37 | + |
| 38 | +Explain what a reference type is and how it constrasts with a value type. |
| 39 | + |
| 40 | +## Foundational: Using reference types to avoid copies |
| 41 | + |
| 42 | +### Background/Required Knowledge |
| 43 | + |
| 44 | +A student is able to: |
| 45 | + |
| 46 | +* Define and call a function with parameters |
| 47 | + |
| 48 | +### Student outcomes |
| 49 | + |
| 50 | +_A list of things "a student should be able to" after the curriculum._ |
| 51 | +_The next word should be an action word and testable in an exam._ |
| 52 | +_Max 5 items._ |
| 53 | + |
| 54 | +A student should be able to: |
| 55 | + |
| 56 | +1. Use const-refernce types for function arguments |
| 57 | +2. Explain what considerations to take when deciding whether or not to use a const-reference type |
| 58 | + |
| 59 | +### Caveats |
| 60 | + |
| 61 | +_This section mentions subtle points to understand, like anything resulting in |
| 62 | +implementation-defined, unspecified, or undefined behavior._ |
| 63 | + |
| 64 | +### Points to cover |
| 65 | + |
| 66 | +_This section lists important details for each point._ |
| 67 | + |
| 68 | +* No copy of the data is made when taken by constant reference |
| 69 | +* A constant reference value cannot be modified |
| 70 | +* The lifetime of a constant reference cannot be expected to extend beyond the lifetime of the function, so the reference should not be saved off for future use. |
| 71 | +* Taking a reference is not always a time or space savings. Modern machines may use 8-bytes to reference a 4-byte integer, for instance. |
| 72 | + |
| 73 | +## Main: Using references to modify external data |
| 74 | + |
| 75 | +### Background/Required Knowledge |
| 76 | + |
| 77 | +* All of the above |
| 78 | + |
| 79 | +### Student outcomes |
| 80 | + |
| 81 | +A student should be able to: |
| 82 | + |
| 83 | +1. Define and utilize a non-const reference for passing values out of a function |
| 84 | + |
| 85 | +### Caveats |
| 86 | + |
| 87 | +### Points to cover |
| 88 | + |
| 89 | +* If the function does not intend to modify the value, const-references should be preferred |
| 90 | +* A reference value may be modified |
| 91 | +* The lifetime of a reference cannot be expected to extend beyond the lifetime of the function, so the reference should not be saved off for future use. |
| 92 | +* Taking a reference is not always a time or space savings. Modern machines may use 8-bytes to reference a 4-byte integer, for instance. |
| 93 | + |
| 94 | +## Advanced |
| 95 | + |
| 96 | +_These are important topics that are not expected to be covered but provide |
| 97 | +guidance where one can continue to investigate this topic in more depth._ |
| 98 | + |
0 commit comments