From 70a0a981440c29dab185bbb5ac2e6a0ff396dbba Mon Sep 17 00:00:00 2001 From: Nick Krichevsky Date: Mon, 14 Dec 2020 13:16:49 -0500 Subject: [PATCH] Add move constructor to day 14 --- day14/day14.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/day14/day14.cpp b/day14/day14.cpp index d4a78d9..b163358 100644 --- a/day14/day14.cpp +++ b/day14/day14.cpp @@ -17,10 +17,14 @@ constexpr auto MEM_PATTERN = R"(mem\[(\d+)\] = (\d+))"; */ class InstructionBlock { public: - InstructionBlock(std::string mask, std::vector> storeInstructions) + InstructionBlock(const std::string &mask, const std::vector> &storeInstructions) : mask(mask), storeInstructions(storeInstructions) { } + InstructionBlock(std::string &&mask, std::vector> &&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 * @param num The number to mask @@ -134,7 +138,7 @@ std::vector parseInput(const std::vector &input) if (std::regex_match(line, matches, maskExpression)) { // We don't want to emplace on the first mask we find if (it != input.cbegin()) { - blocks.emplace_back(currentMask, currentStoreInstructions); + blocks.emplace_back(std::move(currentMask), std::move(currentStoreInstructions)); currentStoreInstructions.clear(); } @@ -147,7 +151,7 @@ std::vector parseInput(const std::vector &input) } // Put in the last one we've found - blocks.emplace_back(currentMask, currentStoreInstructions); + blocks.emplace_back(std::move(currentMask), std::move(currentStoreInstructions)); return blocks; }