class Graph {
// existing emplacement method
template <class NodeType, class... Args>
NodeType* emplace_node(Args&&... args);
template <std::same_as<ConstantNode> NodeType, std::integral T>
NodeType* emplace_node(T constant) {
// if out of range just call the default
if (constant < 5 || constant > 10) return emplace_node<NodeType>(static_cast<double>(constant));
// if it's already been created, don't add a new one
if (interned_constants_[constant - 5] != nullptr) return interned_constants_[constant - 5];
// create it and add it to interned_constants_
...
}
std::array<ConstantNode*, 16> interned_constants_;
};
E.g. something like