From ec0c42a4ede7913089bbc0d860c7fa381d4989f8 Mon Sep 17 00:00:00 2001 From: rwdougla Date: Thu, 8 Jun 2023 04:37:46 -0500 Subject: [PATCH 1/4] Introduces topic for Passing Parameters by Value (#72) resolves #38 Co-authored-by: Florian Sattler --- .../functions/passing-parameters-by-value.md | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 sources/modules/functions/passing-parameters-by-value.md diff --git a/sources/modules/functions/passing-parameters-by-value.md b/sources/modules/functions/passing-parameters-by-value.md new file mode 100644 index 0000000..a45b0e9 --- /dev/null +++ b/sources/modules/functions/passing-parameters-by-value.md @@ -0,0 +1,91 @@ +# Module name: Passing Parameters by Value +_Skeleton descriptions are typeset in italic text,_ +_so please don't remove these descriptions when editing the topic._ + +## Overview + +_Provides a short natural language abstract of the module’s contents._ +_Specifies the different levels of teaching._ + + + + + + + + + + + + + + + + + + +
LevelObjectives
FoundationalDefining and calling functions with values
Main
Advanced
+ +## Motivation + +_Why is this important?_ +_Why do we want to learn/teach this topic?_ + +The fundamental element for code-reuse is a function. For functions to be +useful, we need to parameterize them. Understanding how to do such is thus +fundamental to programming in any language. + +## Topic introduction + +_Very brief introduction to the topic._ + +Explain how to define functions with parameters and call them with values. + +## Foundational: Using reference types to avoid copies + +### Background/Required Knowledge + +A student is able to: + +* Explain what a function is + +### Student outcomes + +_A list of things "a student should be able to" after the curriculum._ +_The next word should be an action word and testable in an exam._ +_Max 5 items._ + +A student should be able to: + +1. Call a function with any number of parameters using the same number of arguments +2. Define a function with any number of parameters + +### Caveats + +_This section mentions subtle points to understand, like anything resulting in +implementation-defined, unspecified, or undefined behavior._ + +### Points to cover + +_This section lists important details for each point._ + +* A function is called by invoking the name of the function, followed by parentheses +* For each parameter in the function signature, a value must be provided, and in the same order +* Multiple values passed to a function are comma-separated +* When defining a function, you must list the parameters with the type first, and parameter name second + +## Main: Using references to modify external data + +### Background/Required Knowledge + +### Student outcomes + +### Caveats + +### Points to cover + +## Advanced + +_These are important topics that are not expected to be covered but provide +guidance where one can continue to investigate this topic in more depth._ + From 1a23e85d9ed238ee2b8808fba7c3aa4d689900e2 Mon Sep 17 00:00:00 2001 From: rwdougla Date: Thu, 8 Jun 2023 04:39:26 -0500 Subject: [PATCH 2/4] Initial topic for passing parameters by reference (#71) resolves #39 --- .../passing-parameters-by-reference.md | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 sources/modules/functions/passing-parameters-by-reference.md diff --git a/sources/modules/functions/passing-parameters-by-reference.md b/sources/modules/functions/passing-parameters-by-reference.md new file mode 100644 index 0000000..aebdec6 --- /dev/null +++ b/sources/modules/functions/passing-parameters-by-reference.md @@ -0,0 +1,98 @@ +# Module name: Passing Parameters by Reference +_Skeleton descriptions are typeset in italic text,_ +_so please don't remove these descriptions when editing the topic._ + +## Overview + +_Provides a short natural language abstract of the module’s contents._ +_Specifies the different levels of teaching._ + + + + + + + + + + + + + + + + + + +
LevelObjectives
FoundationalAvoiding copies using const-reference modifiers
MainUsing references to modify external data
Advanced
+ +## Motivation + +_Why is this important?_ +_Why do we want to learn/teach this topic?_ + +## Topic introduction + +_Very brief introduction to the topic._ + +Explain what a reference type is and how it constrasts with a value type. + +## Foundational: Using reference types to avoid copies + +### Background/Required Knowledge + +A student is able to: + +* Define and call a function with parameters + +### Student outcomes + +_A list of things "a student should be able to" after the curriculum._ +_The next word should be an action word and testable in an exam._ +_Max 5 items._ + +A student should be able to: + +1. Use const-refernce types for function arguments +2. Explain what considerations to take when deciding whether or not to use a const-reference type + +### Caveats + +_This section mentions subtle points to understand, like anything resulting in +implementation-defined, unspecified, or undefined behavior._ + +### Points to cover + +_This section lists important details for each point._ + +* No copy of the data is made when taken by constant reference +* A constant reference value cannot be modified +* 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. +* 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. + +## Main: Using references to modify external data + +### Background/Required Knowledge + +* All of the above + +### Student outcomes + +A student should be able to: + +1. Define and utilize a non-const reference for passing values out of a function + +### Caveats + +### Points to cover + +* If the function does not intend to modify the value, const-references should be preferred +* A reference value may be modified +* 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. +* 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. + +## Advanced + +_These are important topics that are not expected to be covered but provide +guidance where one can continue to investigate this topic in more depth._ + From ce762bbbf7cbc4db2ac67aafb2a88c052788743d Mon Sep 17 00:00:00 2001 From: Florian Sattler Date: Thu, 8 Jun 2023 13:39:32 +0200 Subject: [PATCH 3/4] Fixes document building during release triggered by a tag (#84) --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 81988c2..486c47c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -23,7 +23,7 @@ jobs: - name: Collect git metadata id: git_metadata run: | - echo "{VERSION}::{${GITHUB_REF#refs/tags/v}}" >> $GITHUB_OUTPUT + echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT # The following builds the document in multiple formats for deployment. - name: Build the document. shell: bash From ab3c4bee58daadf98161064eba1b914db60a91ca Mon Sep 17 00:00:00 2001 From: Frank Birbacher Date: Wed, 14 Jun 2023 23:42:50 +0300 Subject: [PATCH 4/4] Create overview for UDL (#86) Introduce the UDL abbreviation and describe the feature in the overview of the topic. --- sources/modules/functions/user-defined-literals.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sources/modules/functions/user-defined-literals.md b/sources/modules/functions/user-defined-literals.md index bb1bcd6..a9894ed 100644 --- a/sources/modules/functions/user-defined-literals.md +++ b/sources/modules/functions/user-defined-literals.md @@ -1,4 +1,4 @@ -## Functions: user-defined literals {#udl} +## Functions: user-defined literals (UDL) {#udl} _Skeleton descriptions are typeset in italic text,_ _so please don't remove these descriptions when editing the topic._ @@ -8,6 +8,11 @@ _so please don't remove these descriptions when editing the topic._ _Provides a short natural language abstract of the module’s contents._ _Specifies the different levels of teaching._ +Literals are a way to write values in the code, such as strings and numbers. +User-defined literals (UDL) allow to add a suffix to a string or number to change the meaning. +The suffix selects a function (an operator) that can alter the value and type of the literal. +The C++ library provides certain operators already and a user can add more by providing such operators. + ------------------------------------------------------------------------- Level Objectives ---------------- --------------------------------------------------------