Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions phlex/model/products.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
#include "phlex/model/product_specification.hpp"

#include <cassert>
#include <cstring>
#include <memory>
#include <string>
#include <typeindex>
#include <unordered_map>
#include <utility>
#include <variant>

namespace phlex::experimental {

Expand Down Expand Up @@ -77,18 +75,10 @@ namespace phlex::experimental {
throw std::runtime_error("No product exists with the name '" + product_name + "'.");
}

// Should be able to use dynamic_cast a la:
//
// if (auto t = dynamic_cast<product<T> const*>(it->second.get())) {
// return t->obj;
// }
//
// Unfortunately, this doesn't work well whenever products are inserted across
// modules and shared object libraries.

auto available_product = it->second.get();
if (std::strcmp(typeid(T).name(), available_product->type().name()) == 0) {
return reinterpret_cast<product<T> const*>(available_product)->obj;
auto const* available_product = it->second.get();

if (auto const* desired_product = dynamic_cast<product<T> const*>(available_product)) {
return desired_product->obj;
}

throw_mismatched_type(product_name, typeid(T).name(), available_product->type().name());
Expand Down
Loading