-
-
Notifications
You must be signed in to change notification settings - Fork 708
Document that Iterator(image, region) constructors initialize at the begin, add GTest unit test #4815
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
Document that Iterator(image, region) constructors initialize at the begin, add GTest unit test #4815
Conversation
c02faaa
to
bc2a55e
Compare
Checks that an iterator, constructed by `IteratorType(image, region)` is at the begin. Checks 22 different iterator types from Core/Common.
Explicitly specify that those constructors initialize the iterator at the begin of the region.
bc2a55e
to
88b854f
Compare
It is unnecessary to call GoToBegin() on an ITK iterator when it has just been constructed, by `Iterator(image, region)`. Such a function call just takes compile-time and run-time. Supported by ITK pull request InsightSoftwareConsortium/ITK#4815 "Document that Iterator(image, region) constructors initialize at the begin, add GTest unit test"
// Has_IsAtBegin tells whether the specified iterator type has an `IsAtBegin()` member function, returning a `bool`. It | ||
// is inspired by "How to detect whether there is a specific member variable in class?", answered by Andy Prowl, Jan 25, | ||
// 2013 at https://stackoverflow.com/a/14523787 (the `has_id` example). | ||
template <typename TIterator, typename = bool> | ||
struct Has_IsAtBegin : std::false_type | ||
{}; | ||
|
||
template <typename TIterator> | ||
struct Has_IsAtBegin<TIterator, decltype(std::declval<TIterator>().IsAtBegin())> : std::true_type | ||
{}; |
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.
- Fun fact: I found this "has member" trick (
Has_IsAtBegin
) kind-of independent ofhas_Print
andhas_output_operator
, from Bradley's (@blowekamp) pull requests, BUG: Fix printing of values in MetaDataObject #4814 and STYLE: move details to MetaDataObjectDetail #4821
For the record,
- The direct link to the StackOverflow post that I read for this pull request: "How to detect whether there is a specific member variable in class?", answered by Andy Prowl, Jan 25, 2013
has_Print
andhas_output_operator
are atITK/Modules/Core/Common/include/itkMetaDataObjectDetail.h
Lines 31 to 46 in f66d9a4
template <class T, class = void> struct has_Print : std::false_type {}; template <class T> struct has_Print<T, std::void_t<decltype(std::declval<T>().Print(std::declval<std::ostream &>()))>> : std::true_type {}; template <class T, class = void> struct has_output_operator : std::false_type {}; template <class T> struct has_output_operator<T, std::void_t<decltype(std::declval<std::ostream &>() << std::declval<T>())>> : std::true_type {};
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.
Anyway, this Has_IsAtBegin<TIterator>
meta-function is just an implementation detail of the unit test that I'm proposing. As a whole, I think this pull request is ready 😃
It is unnecessary to call GoToBegin() on an ITK iterator when it has just been constructed, by `Iterator(image, region)`. Such a function call just takes compile-time and run-time. Supported by ITK pull request InsightSoftwareConsortium/ITK#4815 "Document that Iterator(image, region) constructors initialize at the begin, add GTest unit test"
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.
LGTM. Just a commented on a small thought.
|
||
|
||
// Checks that an iterator that is just constructed by `IteratorType(image, region)` is at the begin. | ||
TEST(ImageRegionIterator, IsConstructedAtBegin) |
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.
The is some 💪 use of variadict templates here. However with the nested dispatching of the functions how does test report a failure? Does it indicate the type? Is some Information needed the the "EXPECT" statements?
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.
Thanks, here is my reply: #4815 (comment)
- Follow-up to pull request InsightSoftwareConsortium#4815 commit 66e6d8b "ENH: Add GoogleTest unit test `ImageRegionIterator.IsConstructedAtBegin`"
Explicitly specify that those constructors from iterator types of Modules/Filtering/ImageFrequency initialize the iterator at the begin of the region. - Follow-up to pull request InsightSoftwareConsortium#4815 commit 9eb1359 "DOC: Document Iterator(image, region) constructors initializing at begin"
|
When an ITK iterator is just constructed by `IteratorType(image, region)`, it is already initialized at the begin of the region, as was tested and documented by pull request InsightSoftwareConsortium#4815 commit 66e6d8b and 9eb1359. - Follow-up to pull request InsightSoftwareConsortium#3953 commit 5a60ed0 "STYLE: Remove unnecessary iterator `GoToBegin()` calls from Filtering", 7 March 2023
- Follow-up to pull request InsightSoftwareConsortium#4815 commit 66e6d8b "ENH: Add GoogleTest unit test `ImageRegionIterator.IsConstructedAtBegin`" Note: `FrequencyImageRegionIteratorWithIndex` and `FrequencyImageRegionConstIteratorWithIndex` are excluded from this commit, because they do not yet compile.
Explicitly specify that those constructors from iterator types of Modules/Filtering/ImageFrequency initialize the iterator at the begin of the region. Note: `FrequencyImageRegionIteratorWithIndex` and `FrequencyImageRegionConstIteratorWithIndex` are excluded from this commit, because they do not yet compile. - Follow-up to pull request InsightSoftwareConsortium#4815 commit 9eb1359 "DOC: Document Iterator(image, region) constructors initializing at begin"
When an ITK iterator is just constructed by `IteratorType(image, region)`, it is already initialized at the begin of the region, as was tested and documented by pull request #4815 commit 66e6d8b and 9eb1359. - Follow-up to pull request #3953 commit 5a60ed0 "STYLE: Remove unnecessary iterator `GoToBegin()` calls from Filtering", 7 March 2023
Explicitly specify that those constructors from iterator types of Modules/Filtering/ImageFrequency initialize the iterator at the begin of the region. Note: `FrequencyImageRegionIteratorWithIndex` and `FrequencyImageRegionConstIteratorWithIndex` are excluded from this commit, because they do not yet compile. - Follow-up to pull request #4815 commit 9eb1359 "DOC: Document Iterator(image, region) constructors initializing at begin"
Documented that
Iterator(image, region)
constructors initialize the iterator at the beginning of the region. Added a GoogleTest unit test to checks this added specification.