Skip to content
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

Type#GetLoadDependencies(): VERIFY() that no nullptr is returned #10155

Merged
merged 2 commits into from
Sep 20, 2024

Conversation

Al2Klimov
Copy link
Member

@Al2Klimov Al2Klimov commented Sep 16, 2024

@Al2Klimov Al2Klimov added the core/quality Improve code, libraries, algorithms, inline docs label Sep 16, 2024
@cla-bot cla-bot bot added the cla/signed label Sep 16, 2024
@Al2Klimov Al2Klimov force-pushed the Type-GetLoadDependencies-nullptr branch from 66bb803 to 6a11cf1 Compare September 18, 2024 08:56
If a specific type shall return no deps, the base method already does that.
@Al2Klimov Al2Klimov force-pushed the Type-GetLoadDependencies-nullptr branch 2 times, most recently from 3a77ff8 to d298508 Compare September 19, 2024 14:39
Comment on lines +386 to +387
for (auto& dep : klass.LoadDependencies)
m_Impl << "\t\tauto type" << dep << " (GetByName(\"" << dep << "\").get());" << std::endl;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's much better, but why are you using two different loops for declaring and verifying them? Can't you just combine them like that?

Suggested change
for (auto& dep : klass.LoadDependencies)
m_Impl << "\t\tauto type" << dep << " (GetByName(\"" << dep << "\").get());" << std::endl;
for (auto& dep : klass.LoadDependencies) {
m_Impl << "\t\tauto type" << dep << " (GetByName(\"" << dep << "\").get());" << std::endl;
m_Impl << "\t\tVERIFY(type" << dep << ");" << std::endl;
}
m_Impl << std::endl << "\t\treturn std::unordered_set<Type*>{";

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I prefer this:

const std::unordered_set<Type*>& TypeImpl<Service>::GetLoadDependencies() const
{
	static const auto deps ([] {
		auto typeApiListener (GetByName("ApiListener").get());
		auto typeEndpoint (GetByName("Endpoint").get());
		auto typeHost (GetByName("Host").get());
		auto typeZone (GetByName("Zone").get());

		VERIFY(typeApiListener);
		VERIFY(typeEndpoint);
		VERIFY(typeHost);
		VERIFY(typeZone);

		return std::unordered_set{ typeApiListener, typeEndpoint, typeHost, typeZone, };
	}());

	return deps;
}

Copy link
Member

@yhabteab yhabteab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, let's do this!

@yhabteab yhabteab added this to the 2.15.0 milestone Sep 20, 2024
@yhabteab yhabteab merged commit dac747f into master Sep 20, 2024
26 checks passed
@yhabteab yhabteab deleted the Type-GetLoadDependencies-nullptr branch September 20, 2024 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla/signed core/quality Improve code, libraries, algorithms, inline docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants