3030#include " cucumber/messages/undefined_parameter_type.hpp"
3131#include < cstdint>
3232#include < format>
33+ #include < functional>
3334#include < map>
3435#include < memory>
3536#include < span>
@@ -163,7 +164,7 @@ namespace cucumber_cpp::library
163164 return lineageById.at (pickle.ast_node_ids [0 ]);
164165 }
165166
166- const Lineage& Query::FindLineageByUri (std::string uri) const
167+ const Lineage& Query::FindLineageByUri (const std::string& uri) const
167168 {
168169 return lineageByUri.at (uri);
169170 }
@@ -238,12 +239,12 @@ namespace cucumber_cpp::library
238239 return lineage.scenario ->location ;
239240 }
240241
241- const std::map<std::string, cucumber::messages::test_case_started>& Query::TestCaseStarted () const
242+ const std::map<std::string, cucumber::messages::test_case_started, std::less<> >& Query::TestCaseStarted () const
242243 {
243244 return testCaseStartedById;
244245 }
245246
246- const std::map<std::string, cucumber::messages::test_case_finished>& Query::TestCaseFinishedByTestCaseStartedId () const
247+ const std::map<std::string, cucumber::messages::test_case_finished, std::less<> >& Query::TestCaseFinishedByTestCaseStartedId () const
247248 {
248249 return testCaseFinishedByTestCaseStartedId;
249250 }
@@ -257,19 +258,19 @@ namespace cucumber_cpp::library
257258
258259 void Query::operator +=(const cucumber::messages::pickle& pickle)
259260 {
260- pickleById.emplace (pickle.id , pickle);
261+ pickleById.try_emplace (pickle.id , pickle);
261262 for (const auto & pickleStep : pickle.steps )
262- pickleStepById.emplace (pickleStep.id , pickleStep);
263+ pickleStepById.try_emplace (pickleStep.id , pickleStep);
263264 }
264265
265266 void Query::operator +=(const cucumber::messages::hook& hook)
266267 {
267- hooksById.emplace (hook.id , hook);
268+ hooksById.try_emplace (hook.id , hook);
268269 }
269270
270271 void Query::operator +=(const cucumber::messages::step_definition& stepDefinition)
271272 {
272- stepDefinitionById.emplace (stepDefinition.id , stepDefinition);
273+ stepDefinitionById.try_emplace (stepDefinition.id , stepDefinition);
273274 }
274275
275276 void Query::operator +=(const cucumber::messages::test_run_started& testRunStarted)
@@ -279,23 +280,23 @@ namespace cucumber_cpp::library
279280
280281 void Query::operator +=(const cucumber::messages::test_run_hook_started& testRunHookStarted)
281282 {
282- testRunHookStartedById.emplace (testRunHookStarted.id , testRunHookStarted);
283+ testRunHookStartedById.try_emplace (testRunHookStarted.id , testRunHookStarted);
283284 }
284285
285286 void Query::operator +=(const cucumber::messages::test_run_hook_finished& testRunHookFinished)
286287 {
287- testRunHookFinishedByTestRunHookStartedId.emplace (testRunHookFinished.test_run_hook_started_id , testRunHookFinished);
288+ testRunHookFinishedByTestRunHookStartedId.try_emplace (testRunHookFinished.test_run_hook_started_id , testRunHookFinished);
288289 }
289290
290291 void Query::operator +=(const cucumber::messages::test_case& testCase)
291292 {
292- auto & testCaseRef = testCaseById.emplace (testCase.id , testCase).first ->second ;
293- testCaseByPickleId.emplace (testCase.pickle_id , testCaseRef);
293+ auto & testCaseRef = testCaseById.try_emplace (testCase.id , testCase).first ->second ;
294+ testCaseByPickleId.try_emplace (testCase.pickle_id , testCaseRef);
294295
295296 for (const auto & testStep : testCase.test_steps )
296297 {
297- testStepById.emplace (testStep.id , testStep);
298- pickleIdByTestStepId.emplace (testStep.id , testCase.pickle_id );
298+ testStepById.try_emplace (testStep.id , testStep);
299+ pickleIdByTestStepId.try_emplace (testStep.id , testCase.pickle_id );
299300
300301 if (testStep.pickle_step_id )
301302 {
@@ -310,7 +311,7 @@ namespace cucumber_cpp::library
310311
311312 void Query::operator +=(const cucumber::messages::test_case_started& testCaseStarted)
312313 {
313- testCaseStartedById.emplace (testCaseStarted.id , testCaseStarted);
314+ testCaseStartedById.try_emplace (testCaseStarted.id , testCaseStarted);
314315
315316 /* reset data? https://github.dev/cucumber/query/blob/f31732e5972c1815614f1d83928a7065e3080dc4/javascript/src/Query.ts#L249 */
316317 }
@@ -346,7 +347,7 @@ namespace cucumber_cpp::library
346347
347348 void Query::operator +=(const cucumber::messages::test_case_finished& testCaseFinished)
348349 {
349- testCaseFinishedByTestCaseStartedId.emplace (testCaseFinished.test_case_started_id , testCaseFinished);
350+ testCaseFinishedByTestCaseStartedId.try_emplace (testCaseFinished.test_case_started_id , testCaseFinished);
350351 }
351352
352353 void Query::operator +=(const cucumber::messages::test_run_finished& testRunFinished)
@@ -429,12 +430,12 @@ namespace cucumber_cpp::library
429430 void Query::operator +=(std::span<const cucumber::messages::step> steps)
430431 {
431432 for (const auto & step : steps)
432- stepById.emplace (step.id , step);
433+ stepById.try_emplace (step.id , step);
433434 }
434435
435436 void Query::operator +=(const cucumber::messages::parameter_type& parameterType)
436437 {
437- auto & ref = parameterTypeById.emplace (parameterType.id , parameterType).first ->second ;
438- parameterTypeByName.emplace (parameterType.name , ref);
438+ auto & ref = parameterTypeById.try_emplace (parameterType.id , parameterType).first ->second ;
439+ parameterTypeByName.try_emplace (parameterType.name , ref);
439440 }
440441}
0 commit comments