Skip to content

Commit a772525

Browse files
committed
REF: Use some C++17 features
1 parent 9b18344 commit a772525

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+198
-299
lines changed

examples/historical/metadata.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ int main() {
4949

5050
const auto all_unit_prices = client.MetadataListUnitPrices(kGlbxMdp3);
5151
std::cout << "Unit prices:\n";
52-
for (const auto& mode_and_prices : all_unit_prices) {
53-
const auto* mode_str = ToString(mode_and_prices.mode);
54-
for (const auto& schema_and_price : mode_and_prices.unit_prices) {
55-
std::cout << "- (" << mode_str << ", " << schema_and_price.first
56-
<< "): " << schema_and_price.second << '\n';
52+
for (const auto& [mode, unit_prices] : all_unit_prices) {
53+
const auto* mode_str = ToString(mode);
54+
for (const auto [schema, price] : unit_prices) {
55+
std::cout << "- (" << mode_str << ", " << schema << "): " << price
56+
<< '\n';
5757
}
5858
}
5959
std::cout << '\n';

examples/live/live_smoke_test.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <sstream>
1212
#include <stdexcept>
1313
#include <string>
14-
#include <unordered_map>
1514

1615
using namespace databento;
1716

@@ -28,7 +27,6 @@ std::vector<std::string> SplitSymbols(const std::string& symbols) {
2827
}
2928

3029
std::pair<bool, UnixNanos> TryConvertToUnixNanos(const char* start) {
31-
std::stringstream ss(start);
3230
std::size_t pos;
3331
const uint64_t result = std::stoul(start, &pos, 10);
3432
if (pos != std::strlen(start)) {
@@ -187,10 +185,10 @@ int main(int argc, char* argv[]) {
187185
if (use_snapshot) {
188186
client.SubscribeWithSnapshot(symbols, schema, stype);
189187
} else if (start) {
190-
const auto converted = TryConvertToUnixNanos(start);
191-
if (converted.first) {
192-
start_from_epoch = converted.second.time_since_epoch().count() == 0;
193-
client.Subscribe(symbols, schema, stype, converted.second);
188+
const auto [success, start_nanos] = TryConvertToUnixNanos(start);
189+
if (success) {
190+
start_from_epoch = start_nanos.time_since_epoch().count() == 0;
191+
client.Subscribe(symbols, schema, stype, start_nanos);
194192
} else {
195193
client.Subscribe(symbols, schema, stype, start);
196194
}

examples/live/simple.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ static std::sig_atomic_t volatile gSignal;
1616

1717
int main() {
1818
databento::PitSymbolMap symbol_mappings;
19-
std::unique_ptr<databento::ILogReceiver> log_receiver{
20-
new databento::ConsoleLogReceiver{databento::LogLevel::Debug}};
19+
auto log_receiver = std::make_unique<databento::ConsoleLogReceiver>(
20+
databento::LogLevel::Debug);
2121

2222
auto client = databento::LiveBuilder{}
2323
.SetLogReceiver(log_receiver.get())

include/databento/detail/json_helpers.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ namespace httplib {
1515
using Params = std::multimap<std::string, std::string>;
1616
}
1717

18-
namespace databento {
19-
namespace detail {
18+
namespace databento::detail {
2019
void SetIfNotEmpty(httplib::Params* params, const std::string& key,
2120
const std::string& value);
2221
void SetIfNotEmpty(httplib::Params* params, const std::string& key,
@@ -95,5 +94,4 @@ date::year_month_day ParseAt(const std::string& endpoint,
9594
const nlohmann::json& json,
9695
const std::string& key);
9796

98-
} // namespace detail
99-
} // namespace databento
97+
} // namespace databento::detail

include/databento/detail/scoped_fd.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
#include <winsock2.h> // SOCKET
55
#endif
66

7-
namespace databento {
8-
namespace detail {
7+
namespace databento::detail {
98
#ifdef _WIN32
109
using Socket = SOCKET;
1110
#else
@@ -35,5 +34,4 @@ class ScopedFd {
3534
private:
3635
Socket fd_{kUnset};
3736
};
38-
} // namespace detail
39-
} // namespace databento
37+
} // namespace databento::detail

include/databento/detail/scoped_thread.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
#include <thread>
44
#include <utility> // forward, move
55

6-
namespace databento {
7-
namespace detail {
6+
namespace databento::detail {
87
// An RAII thread that joins if necessary on destruction, like std::jthread in
98
// C++20.
109
class ScopedThread {
@@ -37,5 +36,4 @@ class ScopedThread {
3736
private:
3837
std::thread thread_;
3938
};
40-
} // namespace detail
41-
} // namespace databento
39+
} // namespace databento::detail

include/databento/detail/shared_channel.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
#include "databento/ireadable.hpp"
88

9-
namespace databento {
10-
namespace detail {
9+
namespace databento::detail {
1110
// Copyable, thread-safe, unidirectional channel.
1211
class SharedChannel : public IReadable {
1312
public:
@@ -28,5 +27,4 @@ class SharedChannel : public IReadable {
2827

2928
std::shared_ptr<Channel> channel_;
3029
};
31-
} // namespace detail
32-
} // namespace databento
30+
} // namespace databento::detail

include/databento/detail/tcp_client.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
#include "databento/detail/scoped_fd.hpp" // ScopedFd
88

9-
namespace databento {
10-
namespace detail {
9+
namespace databento::detail {
1110
class TcpClient {
1211
public:
1312
enum class Status : std::uint8_t {
@@ -47,5 +46,4 @@ class TcpClient {
4746

4847
ScopedFd socket_;
4948
};
50-
} // namespace detail
51-
} // namespace databento
49+
} // namespace databento::detail

include/databento/detail/zstd_stream.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
#include "databento/iwritable.hpp"
1212
#include "databento/log.hpp"
1313

14-
namespace databento {
15-
namespace detail {
14+
namespace databento::detail {
1615
class ZstdDecodeStream : public IReadable {
1716
public:
1817
explicit ZstdDecodeStream(std::unique_ptr<IReadable> input);
@@ -54,5 +53,4 @@ class ZstdCompressStream : public IWritable {
5453
std::size_t in_size_;
5554
std::vector<std::uint8_t> out_buffer_;
5655
};
57-
} // namespace detail
58-
} // namespace databento
56+
} // namespace databento::detail

include/databento/record.hpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,10 @@ struct RecordHeader {
4646
};
4747

4848
// Type trait helper for templated functions accepting DBN records.
49-
namespace detail {
50-
// std::void_t added in C++17
51-
template <typename... Ts>
52-
using void_t = void;
53-
} // namespace detail
54-
template <typename, typename = detail::void_t<>>
49+
template <typename, typename = std::void_t<>>
5550
struct has_header : std::false_type {};
5651
template <typename T>
57-
struct has_header<T, detail::void_t<decltype(std::declval<T>().hd)>>
52+
struct has_header<T, std::void_t<decltype(std::declval<T>().hd)>>
5853
: std::is_same<decltype(std::declval<T>().hd), RecordHeader> {};
5954

6055
class Record {

0 commit comments

Comments
 (0)