From 7e9f1b8f47d57048ed1a1286ed13a249b3d720fb Mon Sep 17 00:00:00 2001 From: Jack Bond-Preston Date: Sat, 1 Dec 2018 22:44:45 +0000 Subject: [PATCH] Use set.insert retval to determine duplicate values --- aoc-1/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aoc-1/main.cpp b/aoc-1/main.cpp index 627f3a2..fd1ffce 100644 --- a/aoc-1/main.cpp +++ b/aoc-1/main.cpp @@ -33,11 +33,11 @@ int main() { in.seekg(0, std::ios::beg); while (std::getline(in, line) && !reoccurence_found) { - if (seen_values.find(total) != seen_values.end()) { // if total is already in set + auto result = seen_values.insert(total); // add it to set + if (!result.second) { // if it could not be inserted first_reocurrence = total; reoccurence_found = true; } - else seen_values.insert(total); // add it to set long value = std::stol(line);