diff --git a/.clang-tidy b/.clang-tidy index 19e42e069..59b47c4ba 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -13,6 +13,7 @@ WarningsAsErrors: '*' HeaderFilterRegex: '' UseColor: true FormatStyle: 'file' +ExtraArgs: ['-std=c++17'] CheckOptions: modernize-use-nullptr.NullMacros: 'NULL' # std::exception_ptr is a cheap to copy, pointer-like type; we pass it by value all the time. diff --git a/cpp/DataStorm/clock/Writer.cpp b/cpp/DataStorm/clock/Writer.cpp index 31a6b7fcb..add8985ed 100644 --- a/cpp/DataStorm/clock/Writer.cpp +++ b/cpp/DataStorm/clock/Writer.cpp @@ -33,7 +33,7 @@ namespace DataStorm static chrono::system_clock::time_point decode(const Ice::ByteSeq&) { assert(false); // Not used by the reader but it still needs to be declared. - return chrono::system_clock::time_point(); + return {}; } }; }; diff --git a/cpp/DataStorm/stock/Reader.cpp b/cpp/DataStorm/stock/Reader.cpp index b3776a002..b5213e56d 100644 --- a/cpp/DataStorm/stock/Reader.cpp +++ b/cpp/DataStorm/stock/Reader.cpp @@ -44,16 +44,16 @@ main(int argc, char* argv[]) // Get the set of stocks connected with the any reader and display their ticker. std::promise p; stocks.onConnectedKeys( - [&p](vector tickers) + [&p](const vector& tickers) { cout << "Available stock(s): " << endl; - for (auto ticker : tickers) + for (const auto& ticker : tickers) { cout << ticker << endl; } p.set_value(); }, - [](DataStorm::CallbackReason action, string ticker) + [](DataStorm::CallbackReason action, const string& ticker) { if (action == DataStorm::CallbackReason::Connect) { @@ -90,11 +90,11 @@ main(int argc, char* argv[]) // Wait for the writer to be connected. reader->waitForWriters(); - auto displaySample = [](DataStorm::Sample s) + auto displaySample = [](const DataStorm::Sample& s) { if (s.getEvent() == DataStorm::SampleEvent::Add || s.getEvent() == DataStorm::SampleEvent::Update) { - auto value = s.getValue(); + const auto& value = s.getValue(); cout << "Stock: " << value.name << " (" << s.getKey() << ")" << endl; cout << "Price: " << value.price << endl; cout << "Best bid/ask: " << value.bestBid << '/' << value.bestAsk << endl; diff --git a/cpp/DataStorm/stock/Writer.cpp b/cpp/DataStorm/stock/Writer.cpp index 04636b1d8..7f3d53e22 100644 --- a/cpp/DataStorm/stock/Writer.cpp +++ b/cpp/DataStorm/stock/Writer.cpp @@ -14,20 +14,19 @@ using namespace Demo; namespace { - - std::random_device random; - DataStorm::SingleKeyWriter - makeStock(DataStorm::Topic& topic, string ticker, Stock stock) + makeStock(DataStorm::Topic& topic, const string& ticker, const Stock& stock) { // Create a stock writer for the given ticker and add the initial stock value. - auto writer = DataStorm::makeSingleKeyWriter(topic, std::move(ticker)); - writer.add(std::move(stock)); + auto writer = DataStorm::makeSingleKeyWriter(topic, ticker); + writer.add(stock); return writer; } void updateStock(DataStorm::SingleKeyWriter& stock) { + static std::random_device random; + // Send a partial update to either update the price or the volume with the given writer. if (uniform_int_distribution(1, 10)(random) < 8) { @@ -41,7 +40,6 @@ namespace uniform_int_distribution(volume * 95 / 100, volume * 105 / 100)(random)); } } - } int @@ -140,7 +138,7 @@ main(int argc, char* argv[]) cout << "unknown stock `" << stockName << "'" << endl; return 1; } - writers.push_back(makeStock(topic, std::move(stockName), stocks[stockName])); + writers.push_back(makeStock(topic, stockName, stocks[stockName])); } // Update the stock value or volume attributes.