Skip to content

Commit 825a0c3

Browse files
committed
fixed the ability to overwrite of a trade builder with a new one
1 parent 62f85de commit 825a0c3

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

OREData/ored/portfolio/tradefactory.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@ boost::shared_ptr<AbstractTradeBuilder> TradeFactory::getBuilder(const std::stri
4141
void TradeFactory::addBuilder(const std::string& className, const boost::shared_ptr<AbstractTradeBuilder>& builder,
4242
const bool allowOverwrite) {
4343
boost::unique_lock<boost::shared_mutex> lock(mutex_);
44-
QL_REQUIRE(builders_.insert(std::make_pair(className, builder)).second || allowOverwrite,
45-
"TradeFactory: duplicate builder for className '" << className << "'.");
44+
{
45+
auto [it, ins] = builders_.try_emplace(className, builder);
46+
if (!ins) QL_REQUIRE(allowOverwrite && (it->second = builder),
47+
"TradeFactory: duplicate builder for className '" << className << "'.");
48+
}
4649
}
4750

4851
boost::shared_ptr<Trade> TradeFactory::build(const string& className) const { return getBuilder(className)->build(); }

0 commit comments

Comments
 (0)