Skip to content

Commit

Permalink
Enhanced assertion message.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimitri Rusin committed Nov 28, 2023
1 parent 21ba4ba commit 54654d9
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion include/ioh/common/factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,18 @@ namespace ioh::common
void include(const std::string &name, const int id, Creator creator)
{
const auto already_defined = name_map.find(name) != std::end(name_map);
assert(!already_defined && name.c_str());

// Enhanced assertion message
if (already_defined) {
std::string error_message = "Error: The name '" + name + "' has already been defined in the factory.";

// Output the error message to both std::cerr and std::cout
std::cerr << error_message << std::endl;
std::cout << error_message << std::endl;

assert(false);
}

name_map[name] = std::move(creator);
if (!already_defined)
id_map[check_or_get_next_available(id)] = name;
Expand Down

0 comments on commit 54654d9

Please sign in to comment.