1. David Stone
  2. Technical Machine

Commits

David Stone  committed bfa2239

Improved exception-safety in out-of-memory conditions.

  • Participants
  • Parent commits 9ed3c73
  • Branches default

Comments (0)

Files changed (1)

File source/clients/network/battles.hpp

View file
  • Ignore whitespace
 
 class Battles {
 	public:
-		template<typename Battle, typename ... Args>
-		Battle const & add_pending_challenge(std::string const & opponent, Args && ... args) {
-			auto * battle = new Battle(opponent, std::forward<Args>(args)...);
-			challenges.insert(std::make_pair(opponent, Pointer(battle)));
-			return *battle;
+		template<typename SpecificBattle, typename ... Args>
+		SpecificBattle const & add_pending_challenge(std::string const & opponent, Args && ... args) {
+			Pointer battle_ptr(new SpecificBattle(opponent, std::forward<Args>(args)...));
+			auto const & battle = static_cast<SpecificBattle const &>(*battle_ptr);
+			challenges.insert(std::make_pair(opponent, std::move(battle_ptr)));
+			return battle;
 		}
 		void handle_challenge_withdrawn();
 		void handle_challenge_withdrawn(std::string const & opponent);