From d857685e74ee7ee17fbd2c90c6c4590225fec76b Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 14 Oct 2021 01:30:54 -0400 Subject: [PATCH] use emplace_back() instead of push_back() --- src/BOCS/fix_bocs.cpp | 2 +- src/MEAM/pair_meam.cpp | 2 +- src/ML-RANN/pair_rann.cpp | 2 +- tools/lammps-shell/lammps-shell.cpp | 22 ++++++++++---------- unittest/force-styles/test_config_reader.cpp | 4 ++-- unittest/force-styles/test_pair_style.cpp | 2 +- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/BOCS/fix_bocs.cpp b/src/BOCS/fix_bocs.cpp index 786ff216b0..61339cd31a 100644 --- a/src/BOCS/fix_bocs.cpp +++ b/src/BOCS/fix_bocs.cpp @@ -637,7 +637,7 @@ int FixBocs::read_F_table( char *filename, int p_basis_type ) char line[MAX_F_TABLE_LINE_LENGTH]; std::vector inputLines; while (fgets(line, MAX_F_TABLE_LINE_LENGTH, fpi)) { - inputLines.push_back(std::string(line)); + inputLines.emplace_back(line); } fclose(fpi); diff --git a/src/MEAM/pair_meam.cpp b/src/MEAM/pair_meam.cpp index 2acf58f738..b69d17f0a9 100644 --- a/src/MEAM/pair_meam.cpp +++ b/src/MEAM/pair_meam.cpp @@ -255,7 +255,7 @@ void PairMEAM::coeff(int narg, char **arg) "'maxelt' in meam.h and recompile.", maxelt); for (int i = 0; i < nlibelements; i++) { - libelements.push_back(arg[i+3]); + libelements.emplace_back(arg[i+3]); mass.push_back(0.0); } diff --git a/src/ML-RANN/pair_rann.cpp b/src/ML-RANN/pair_rann.cpp index 60ed776c41..fbc54e745f 100644 --- a/src/ML-RANN/pair_rann.cpp +++ b/src/ML-RANN/pair_rann.cpp @@ -432,7 +432,7 @@ void PairRANN::read_atom_types(std::vector line,char *filename,int int nwords = line.size(); if (nwords < 1) error->one(filename,linenum,"Incorrect syntax for atom types"); nelements = nwords; - line.push_back("all"); + line.emplace_back("all"); allocate(line); } diff --git a/tools/lammps-shell/lammps-shell.cpp b/tools/lammps-shell/lammps-shell.cpp index df8d52bd33..d03e1da70b 100644 --- a/tools/lammps-shell/lammps-shell.cpp +++ b/tools/lammps-shell/lammps-shell.cpp @@ -563,24 +563,24 @@ static void init_commands() // store internal commands int ncmds = sizeof(cmdlist) / sizeof(const char *); for (int i = 0; i < ncmds; ++i) - commands.push_back(cmdlist[i]); + commands.emplace_back(cmdlist[i]); // store optional commands from command styles ncmds = lammps_style_count(lmp, "command"); for (int i = 0; i < ncmds; ++i) { - if (lammps_style_name(lmp, "command", i, buf, BUFLEN)) commands.push_back(buf); + if (lammps_style_name(lmp, "command", i, buf, BUFLEN)) commands.emplace_back(buf); } // store LAMMPS shell specific command names - commands.push_back("help"); - commands.push_back("exit"); - commands.push_back("pwd"); - commands.push_back("cd"); - commands.push_back("mem"); - commands.push_back("source"); - commands.push_back("history"); - commands.push_back("clear_history"); - commands.push_back("save_history"); + commands.emplace_back("help"); + commands.emplace_back("exit"); + commands.emplace_back("pwd"); + commands.emplace_back("cd"); + commands.emplace_back("mem"); + commands.emplace_back("source"); + commands.emplace_back("history"); + commands.emplace_back("clear_history"); + commands.emplace_back("save_history"); // set name so there can be specific entries in ~/.inputrc rl_readline_name = "lammps-shell"; diff --git a/unittest/force-styles/test_config_reader.cpp b/unittest/force-styles/test_config_reader.cpp index 726bd90a93..945c16c649 100644 --- a/unittest/force-styles/test_config_reader.cpp +++ b/unittest/force-styles/test_config_reader.cpp @@ -86,7 +86,7 @@ void TestConfigReader::prerequisites(const yaml_event_t &event) while (1) { data >> key >> value; if (data.eof()) break; - config.prerequisites.push_back(std::make_pair(key, value)); + config.prerequisites.emplace_back(key, value); } } @@ -141,7 +141,7 @@ void TestConfigReader::extract(const yaml_event_t &event) while (1) { data >> name >> value; if (data.eof()) break; - config.extract.push_back(make_pair(name, value)); + config.extract.emplace_back(name, value); } } diff --git a/unittest/force-styles/test_pair_style.cpp b/unittest/force-styles/test_pair_style.cpp index 2eda7bea9f..a2c8424024 100644 --- a/unittest/force-styles/test_pair_style.cpp +++ b/unittest/force-styles/test_pair_style.cpp @@ -1252,7 +1252,7 @@ TEST(PairStyle, single) int argc = sizeof(args) / sizeof(char *); // need to add this dependency - test_config.prerequisites.push_back(std::make_pair("atom", "full")); + test_config.prerequisites.emplace_back("atom", "full"); // create a LAMMPS instance with standard settings to detect the number of atom types if (!verbose) ::testing::internal::CaptureStdout();