-
Notifications
You must be signed in to change notification settings - Fork 18
ENH: Add section "Initializing variables of fixed size array types" #216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
thewtex
merged 1 commit into
InsightSoftwareConsortium:main
from
N-Dekker:InitializingVariablesOfFixedSizeArrayTypes
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1580,6 +1580,9 @@ \section{The auto Keyword} | |
| \section{Initialization and Assignment} | ||
| \label{sec:IniitalizationAndAssignment} | ||
|
|
||
| \subsection{Initialization of member variables} | ||
| \label{subsec:InitializationOfMemberVariables} | ||
|
|
||
| All member variables must be initialized when they are declared. For such | ||
| purpose, brace initializers, e.g. | ||
|
|
||
|
|
@@ -1654,6 +1657,54 @@ \section{Initialization and Assignment} | |
| example \code{FixedArray::m\_InternalArray} and \code{Index::m\_InternalArray} | ||
| do not have a default member initializer. | ||
|
|
||
| \subsection{Initializing variables of fixed size array types} | ||
| \label{subsec:InitializingVariablesOfFixedSizeArrayTypes} | ||
|
|
||
| ITK has various fixed size array types, including template instantiations of | ||
| \code{Index}, \code{Size}, \code{FixedArray}, \code{Point}, and \code{Vector}. | ||
|
|
||
| A variable of such a fixed size array type can be zero-initialized by an empty | ||
| initializer list, `{}`. This is usually the preferred way to initialize the | ||
| variable, when it should initially be filled with zeroes. For example: | ||
|
|
||
| \small | ||
| \begin{minted}[baselinestretch=1,fontsize=\footnotesize,linenos=false,bgcolor=ltgray]{cpp} | ||
| // Declare an index at position (0, 0). | ||
| Index<2> index{}; | ||
|
|
||
| // Declare a point whose coordinates are all 0.0 (the origin). | ||
| PointType origin{}; | ||
| \end{minted} | ||
| \normalsize | ||
|
|
||
| \code{Index} and \code{Size} both have a static `Filled(fillValue)` member | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above about bacticks. |
||
| function, to allow creating a variable that is filled with an arbitrary value. | ||
| For these types, this is usually the preferred way to initialize the variable, | ||
| when it should initially be filled with a value that may be non-zero. For | ||
| example: | ||
|
|
||
| \small | ||
| \begin{minted}[baselinestretch=1,fontsize=\footnotesize,linenos=false,bgcolor=ltgray]{cpp} | ||
| // Declare the index {1, 1, 1}. | ||
| auto index = Index<3>::Filled(1); | ||
|
|
||
| // Declare the size of an 256 x 256 image. | ||
| auto imageSize = Size<2>::Filled(256); | ||
| \end{minted} | ||
| \normalsize | ||
|
|
||
| For other fixed size array types, the function `itk::MakeFilled<T>(fillValue)` | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above about backticks. |
||
| is preferable, when the array should initially be filled with a value that may | ||
| be non-zero. For example: | ||
|
|
||
| \small | ||
| \begin{minted}[baselinestretch=1,fontsize=\footnotesize,linenos=false,bgcolor=ltgray]{cpp} | ||
| // Declare a spacing filled with the value 0.5 (for each direction). | ||
| // SpacingType is typically defined as Vector<double, Dimension>. | ||
| auto spacing = MakeFilled<SpacingType>(0.5); | ||
| \end{minted} | ||
| \normalsize | ||
|
|
||
| \section{Accessing Members} | ||
| \label{sec:Accessing Members} | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`{}` will not highlight the content in LaTeX as you would expect in Markdown: LaTex uses double backticks at the beginning/upright ticks at the end for ticks, simple backticks will render as opening simple ticks both at the beginning/end. To me, the right thing to use here is
\code{}.