Add move constructor to day 14

master
Nick Krichevsky 2020-12-14 13:16:49 -05:00
parent bd820744c8
commit 70a0a98144
1 changed files with 7 additions and 3 deletions

View File

@ -17,10 +17,14 @@ constexpr auto MEM_PATTERN = R"(mem\[(\d+)\] = (\d+))";
*/ */
class InstructionBlock { class InstructionBlock {
public: public:
InstructionBlock(std::string mask, std::vector<std::pair<int, int>> storeInstructions) InstructionBlock(const std::string &mask, const std::vector<std::pair<int, int>> &storeInstructions)
: mask(mask), storeInstructions(storeInstructions) { : mask(mask), storeInstructions(storeInstructions) {
} }
InstructionBlock(std::string &&mask, std::vector<std::pair<int, int>> &&storeInstructions)
: mask(std::move(mask)), storeInstructions(std::move(storeInstructions)) {
}
/** /**
* Mask a value to be stored in memory, in accordance with the mask for this block * Mask a value to be stored in memory, in accordance with the mask for this block
* @param num The number to mask * @param num The number to mask
@ -134,7 +138,7 @@ std::vector<InstructionBlock> parseInput(const std::vector<std::string> &input)
if (std::regex_match(line, matches, maskExpression)) { if (std::regex_match(line, matches, maskExpression)) {
// We don't want to emplace on the first mask we find // We don't want to emplace on the first mask we find
if (it != input.cbegin()) { if (it != input.cbegin()) {
blocks.emplace_back(currentMask, currentStoreInstructions); blocks.emplace_back(std::move(currentMask), std::move(currentStoreInstructions));
currentStoreInstructions.clear(); currentStoreInstructions.clear();
} }
@ -147,7 +151,7 @@ std::vector<InstructionBlock> parseInput(const std::vector<std::string> &input)
} }
// Put in the last one we've found // Put in the last one we've found
blocks.emplace_back(currentMask, currentStoreInstructions); blocks.emplace_back(std::move(currentMask), std::move(currentStoreInstructions));
return blocks; return blocks;
} }