Skip to content

Document and use the fact that SingletonIndex::SetGlobalInstance always returns true#4162

Merged
thewtex merged 4 commits intoInsightSoftwareConsortium:masterfrom
N-Dekker:SetGlobalInstance-returns-true
Sep 5, 2023
Merged

Document and use the fact that SingletonIndex::SetGlobalInstance always returns true#4162
thewtex merged 4 commits intoInsightSoftwareConsortium:masterfrom
N-Dekker:SetGlobalInstance-returns-true

Conversation

@N-Dekker
Copy link
Contributor

@N-Dekker N-Dekker commented Aug 19, 2023

Note that SetGlobalInstance has always just returned true, from the very first commit, pull request #118 commit a66337e ENH: Synchronize factories across modules in Python by Francois Budin (@fbudin69500) and Hans Johnson (@hjmjohnson), February 2019.

Looking at the initial (2019) version of SetGlobalInstance and SetGlobalInstancePrivate:

template<typename T>
bool SetGlobalInstance( const char * globalName, T * global, std::function<void(void*)> func, std::function<void(void)> deleteFunc)
{ return this->SetGlobalInstancePrivate(globalName, global, func, deleteFunc);}

bool
SingletonIndex
::SetGlobalInstancePrivate( const char * globalName, void * global, std::function<void(void*)> func, std::function<void(void)> deleteFunc)
{
m_GlobalObjects.erase(globalName);
m_GlobalObjects.insert(std::make_pair(globalName, std::make_tuple(global, func, deleteFunc) ) );
return true;
}

@github-actions github-actions bot added the area:Core Issues affecting the Core module label Aug 19, 2023
`SingletonIndex::SetGlobalInstancePrivate` did always unconditionally return
`true`, so it might as well just return `void`.
`SingletonIndex::SetGlobalInstance` always returns true, so it is not necessary
to handle the hypothetical case that it /might/ return false.
@N-Dekker N-Dekker force-pushed the SetGlobalInstance-returns-true branch from 01836ea to 6ec6328 Compare August 19, 2023 19:28
@N-Dekker N-Dekker marked this pull request as ready for review August 20, 2023 08:52
@thewtex thewtex merged commit 7fb08b8 into InsightSoftwareConsortium:master Sep 5, 2023
N-Dekker added a commit to N-Dekker/ITK that referenced this pull request Sep 7, 2023
Added overloads of `SetGlobalInstance` and `Singleton` without the unused `func`
parameter. Let the new `SetGlobalInstance` overload just return `void`, instead
of `bool`. Deprecated the original overloads.

Follow-up to:

pull request InsightSoftwareConsortium#4164
commit 6d1c4c7
"STYLE: SingletonIndex does not need to store the unused `func` parameter"

pull request InsightSoftwareConsortium#4162
commit 6ec6328
"STYLE: Let `Singleton` assume that SetGlobalInstance always returns true"
N-Dekker added a commit to N-Dekker/ITK that referenced this pull request Sep 14, 2023
Added overloads of `SetGlobalInstance` and `Singleton` without the unused `func`
parameter. Let the new `SetGlobalInstance` overload just return `void`, instead
of `bool`. Deprecated the original overloads, and made them
`ITK_FUTURE_LEGACY_REMOVE`.

Follow-up to:

pull request InsightSoftwareConsortium#4164
commit 6d1c4c7
"STYLE: SingletonIndex does not need to store the unused `func` parameter"

pull request InsightSoftwareConsortium#4162
commit 6ec6328
"STYLE: Let `Singleton` assume that SetGlobalInstance always returns true"
dzenanz pushed a commit that referenced this pull request Sep 18, 2023
Added overloads of `SetGlobalInstance` and `Singleton` without the unused `func`
parameter. Let the new `SetGlobalInstance` overload just return `void`, instead
of `bool`. Deprecated the original overloads, and made them
`ITK_FUTURE_LEGACY_REMOVE`.

Follow-up to:

pull request #4164
commit 6d1c4c7
"STYLE: SingletonIndex does not need to store the unused `func` parameter"

pull request #4162
commit 6ec6328
"STYLE: Let `Singleton` assume that SetGlobalInstance always returns true"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Core Issues affecting the Core module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants