From 6f9116dfcbed9ce413e5e077f940c7fa2fadf834 Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Thu, 31 Aug 2017 20:25:39 +0000 Subject: [PATCH] Simplified C++ code with vector range constructor. --- cpp/QrCodeGeneratorDemo.cpp | 5 ++--- cpp/QrCodeGeneratorWorker.cpp | 4 +--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/cpp/QrCodeGeneratorDemo.cpp b/cpp/QrCodeGeneratorDemo.cpp index a2c8cfa..befecb0 100644 --- a/cpp/QrCodeGeneratorDemo.cpp +++ b/cpp/QrCodeGeneratorDemo.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -124,9 +125,7 @@ static void doSegmentDemo() { QrCode::Ecc::LOW); printQr(qr2); - std::vector bytes; - for (const char *temp = golden0; *temp != '\0'; temp++) - bytes.push_back(static_cast(*temp)); + std::vector bytes(golden0, golden0 + std::strlen(golden0)); const QrCode qr3 = QrCode::encodeSegments( {QrSegment::makeBytes(bytes), QrSegment::makeNumeric(golden1), QrSegment::makeAlphanumeric(golden2)}, QrCode::Ecc::LOW); diff --git a/cpp/QrCodeGeneratorWorker.cpp b/cpp/QrCodeGeneratorWorker.cpp index 8ca58dc..2033feb 100644 --- a/cpp/QrCodeGeneratorWorker.cpp +++ b/cpp/QrCodeGeneratorWorker.cpp @@ -75,9 +75,7 @@ int main() { // Make list of segments std::vector segs; if (isAscii) { - std::vector text; - for (std::vector::iterator it = data.begin(); it != data.end(); ++it) - text.push_back((char)*it); + std::vector text(data.cbegin(), data.cend()); text.push_back('\0'); segs = QrSegment::makeSegments(text.data()); } else