Skip to content

Commit 54654d9

Browse files
author
Dimitri Rusin
committed
Enhanced assertion message.
1 parent 21ba4ba commit 54654d9

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

include/ioh/common/factory.hpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,18 @@ namespace ioh::common
126126
void include(const std::string &name, const int id, Creator creator)
127127
{
128128
const auto already_defined = name_map.find(name) != std::end(name_map);
129-
assert(!already_defined && name.c_str());
129+
130+
// Enhanced assertion message
131+
if (already_defined) {
132+
std::string error_message = "Error: The name '" + name + "' has already been defined in the factory.";
133+
134+
// Output the error message to both std::cerr and std::cout
135+
std::cerr << error_message << std::endl;
136+
std::cout << error_message << std::endl;
137+
138+
assert(false);
139+
}
140+
130141
name_map[name] = std::move(creator);
131142
if (!already_defined)
132143
id_map[check_or_get_next_available(id)] = name;

0 commit comments

Comments
 (0)