mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
Upgrade to C++20 (#4239)
* Use explicit this capture required by C++20 * Use C++20 span * Replace wpi::numbers with std::numbers * Fix C++20 clang-tidy warning false positive in fmt * Remove ciso646 include since C++20 removed that header * Fix global-buffer-overflow asan warnings in ntcore tests * Add DIOSetProxy constructor to HAL * Upgrade MSVC compiler to 2022 * Bump native-utils to 2023.2.7 (changes to std=c++20) Co-authored-by: Peter Johnson <johnson.peter@gmail.com>
This commit is contained in:
@@ -138,8 +138,8 @@ size_t Base64Decode(std::string_view encoded, std::vector<uint8_t>* plain) {
|
||||
return Base64Decode(os, encoded);
|
||||
}
|
||||
|
||||
span<uint8_t> Base64Decode(std::string_view encoded, size_t* num_read,
|
||||
SmallVectorImpl<uint8_t>& buf) {
|
||||
std::span<uint8_t> Base64Decode(std::string_view encoded, size_t* num_read,
|
||||
SmallVectorImpl<uint8_t>& buf) {
|
||||
buf.clear();
|
||||
raw_usvector_ostream os(buf);
|
||||
*num_read = Base64Decode(os, encoded);
|
||||
@@ -193,19 +193,19 @@ std::string_view Base64Encode(std::string_view plain,
|
||||
return os.str();
|
||||
}
|
||||
|
||||
void Base64Encode(raw_ostream& os, span<const uint8_t> plain) {
|
||||
void Base64Encode(raw_ostream& os, std::span<const uint8_t> plain) {
|
||||
Base64Encode(os, std::string_view{reinterpret_cast<const char*>(plain.data()),
|
||||
plain.size()});
|
||||
}
|
||||
|
||||
void Base64Encode(span<const uint8_t> plain, std::string* encoded) {
|
||||
void Base64Encode(std::span<const uint8_t> plain, std::string* encoded) {
|
||||
encoded->resize(0);
|
||||
raw_string_ostream os(*encoded);
|
||||
Base64Encode(os, plain);
|
||||
os.flush();
|
||||
}
|
||||
|
||||
std::string_view Base64Encode(span<const uint8_t> plain,
|
||||
std::string_view Base64Encode(std::span<const uint8_t> plain,
|
||||
SmallVectorImpl<char>& buf) {
|
||||
buf.clear();
|
||||
raw_svector_ostream os(buf);
|
||||
|
||||
@@ -109,8 +109,8 @@ class DataLog::Buffer {
|
||||
|
||||
size_t GetRemaining() const { return m_maxLen - m_len; }
|
||||
|
||||
wpi::span<uint8_t> GetData() { return {m_buf, m_len}; }
|
||||
wpi::span<const uint8_t> GetData() const { return {m_buf, m_len}; }
|
||||
std::span<uint8_t> GetData() { return {m_buf, m_len}; }
|
||||
std::span<const uint8_t> GetData() const { return {m_buf, m_len}; }
|
||||
|
||||
private:
|
||||
uint8_t* m_buf;
|
||||
@@ -142,12 +142,12 @@ DataLog::DataLog(wpi::Logger& msglog, std::string_view dir,
|
||||
m_newFilename{filename},
|
||||
m_thread{[this, dir = std::string{dir}] { WriterThreadMain(dir); }} {}
|
||||
|
||||
DataLog::DataLog(std::function<void(wpi::span<const uint8_t> data)> write,
|
||||
DataLog::DataLog(std::function<void(std::span<const uint8_t> data)> write,
|
||||
double period, std::string_view extraHeader)
|
||||
: DataLog{defaultMessageLog, std::move(write), period, extraHeader} {}
|
||||
|
||||
DataLog::DataLog(wpi::Logger& msglog,
|
||||
std::function<void(wpi::span<const uint8_t> data)> write,
|
||||
std::function<void(std::span<const uint8_t> data)> write,
|
||||
double period, std::string_view extraHeader)
|
||||
: m_msglog{msglog},
|
||||
m_period{period},
|
||||
@@ -192,7 +192,7 @@ void DataLog::Resume() {
|
||||
m_paused = false;
|
||||
}
|
||||
|
||||
static void WriteToFile(fs::file_t f, wpi::span<const uint8_t> data,
|
||||
static void WriteToFile(fs::file_t f, std::span<const uint8_t> data,
|
||||
std::string_view filename, wpi::Logger& msglog) {
|
||||
do {
|
||||
#ifdef _WIN32
|
||||
@@ -365,7 +365,7 @@ void DataLog::WriterThreadMain(std::string_view dir) {
|
||||
}
|
||||
|
||||
void DataLog::WriterThreadMain(
|
||||
std::function<void(wpi::span<const uint8_t> data)> write) {
|
||||
std::function<void(std::span<const uint8_t> data)> write) {
|
||||
std::chrono::duration<double> periodTime{m_period};
|
||||
|
||||
// write header (version 1.0)
|
||||
@@ -509,7 +509,7 @@ uint8_t* DataLog::StartRecord(uint32_t entry, uint64_t timestamp,
|
||||
return buf;
|
||||
}
|
||||
|
||||
void DataLog::AppendImpl(wpi::span<const uint8_t> data) {
|
||||
void DataLog::AppendImpl(std::span<const uint8_t> data) {
|
||||
while (data.size() > kBlockSize) {
|
||||
uint8_t* buf = Reserve(kBlockSize);
|
||||
std::memcpy(buf, data.data(), kBlockSize);
|
||||
@@ -525,7 +525,7 @@ void DataLog::AppendStringImpl(std::string_view str) {
|
||||
AppendImpl({reinterpret_cast<const uint8_t*>(str.data()), str.size()});
|
||||
}
|
||||
|
||||
void DataLog::AppendRaw(int entry, wpi::span<const uint8_t> data,
|
||||
void DataLog::AppendRaw(int entry, std::span<const uint8_t> data,
|
||||
int64_t timestamp) {
|
||||
if (entry <= 0) {
|
||||
return;
|
||||
@@ -539,7 +539,7 @@ void DataLog::AppendRaw(int entry, wpi::span<const uint8_t> data,
|
||||
}
|
||||
|
||||
void DataLog::AppendRaw2(int entry,
|
||||
wpi::span<const wpi::span<const uint8_t>> data,
|
||||
std::span<const std::span<const uint8_t>> data,
|
||||
int64_t timestamp) {
|
||||
if (entry <= 0) {
|
||||
return;
|
||||
@@ -623,7 +623,7 @@ void DataLog::AppendString(int entry, std::string_view value,
|
||||
timestamp);
|
||||
}
|
||||
|
||||
void DataLog::AppendBooleanArray(int entry, wpi::span<const bool> arr,
|
||||
void DataLog::AppendBooleanArray(int entry, std::span<const bool> arr,
|
||||
int64_t timestamp) {
|
||||
if (entry <= 0) {
|
||||
return;
|
||||
@@ -647,7 +647,7 @@ void DataLog::AppendBooleanArray(int entry, wpi::span<const bool> arr,
|
||||
}
|
||||
}
|
||||
|
||||
void DataLog::AppendBooleanArray(int entry, wpi::span<const int> arr,
|
||||
void DataLog::AppendBooleanArray(int entry, std::span<const int> arr,
|
||||
int64_t timestamp) {
|
||||
if (entry <= 0) {
|
||||
return;
|
||||
@@ -671,12 +671,12 @@ void DataLog::AppendBooleanArray(int entry, wpi::span<const int> arr,
|
||||
}
|
||||
}
|
||||
|
||||
void DataLog::AppendBooleanArray(int entry, wpi::span<const uint8_t> arr,
|
||||
void DataLog::AppendBooleanArray(int entry, std::span<const uint8_t> arr,
|
||||
int64_t timestamp) {
|
||||
AppendRaw(entry, arr, timestamp);
|
||||
}
|
||||
|
||||
void DataLog::AppendIntegerArray(int entry, wpi::span<const int64_t> arr,
|
||||
void DataLog::AppendIntegerArray(int entry, std::span<const int64_t> arr,
|
||||
int64_t timestamp) {
|
||||
if constexpr (wpi::support::endian::system_endianness() ==
|
||||
wpi::support::little) {
|
||||
@@ -709,7 +709,7 @@ void DataLog::AppendIntegerArray(int entry, wpi::span<const int64_t> arr,
|
||||
}
|
||||
}
|
||||
|
||||
void DataLog::AppendFloatArray(int entry, wpi::span<const float> arr,
|
||||
void DataLog::AppendFloatArray(int entry, std::span<const float> arr,
|
||||
int64_t timestamp) {
|
||||
if constexpr (wpi::support::endian::system_endianness() ==
|
||||
wpi::support::little) {
|
||||
@@ -742,7 +742,7 @@ void DataLog::AppendFloatArray(int entry, wpi::span<const float> arr,
|
||||
}
|
||||
}
|
||||
|
||||
void DataLog::AppendDoubleArray(int entry, wpi::span<const double> arr,
|
||||
void DataLog::AppendDoubleArray(int entry, std::span<const double> arr,
|
||||
int64_t timestamp) {
|
||||
if constexpr (wpi::support::endian::system_endianness() ==
|
||||
wpi::support::little) {
|
||||
@@ -775,7 +775,7 @@ void DataLog::AppendDoubleArray(int entry, wpi::span<const double> arr,
|
||||
}
|
||||
}
|
||||
|
||||
void DataLog::AppendStringArray(int entry, wpi::span<const std::string> arr,
|
||||
void DataLog::AppendStringArray(int entry, std::span<const std::string> arr,
|
||||
int64_t timestamp) {
|
||||
if (entry <= 0) {
|
||||
return;
|
||||
@@ -798,7 +798,7 @@ void DataLog::AppendStringArray(int entry, wpi::span<const std::string> arr,
|
||||
}
|
||||
|
||||
void DataLog::AppendStringArray(int entry,
|
||||
wpi::span<const std::string_view> arr,
|
||||
std::span<const std::string_view> arr,
|
||||
int64_t timestamp) {
|
||||
if (entry <= 0) {
|
||||
return;
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
using namespace wpi::log;
|
||||
|
||||
static bool ReadString(wpi::span<const uint8_t>* buf, std::string_view* str) {
|
||||
static bool ReadString(std::span<const uint8_t>* buf, std::string_view* str) {
|
||||
if (buf->size() < 4) {
|
||||
*str = {};
|
||||
return false;
|
||||
@@ -241,7 +241,7 @@ DataLogReader::iterator DataLogReader::begin() const {
|
||||
return DataLogIterator{this, 12 + size};
|
||||
}
|
||||
|
||||
static uint64_t ReadVarInt(wpi::span<const uint8_t> buf) {
|
||||
static uint64_t ReadVarInt(std::span<const uint8_t> buf) {
|
||||
uint64_t val = 0;
|
||||
int shift = 0;
|
||||
for (auto v : buf) {
|
||||
|
||||
@@ -166,20 +166,20 @@ bool wpi::WaitForObject(WPI_Handle handle) {
|
||||
bool wpi::WaitForObject(WPI_Handle handle, double timeout, bool* timedOut) {
|
||||
WPI_Handle signaledValue;
|
||||
auto signaled = WaitForObjects(
|
||||
wpi::span(&handle, 1), wpi::span(&signaledValue, 1), timeout, timedOut);
|
||||
std::span(&handle, 1), std::span(&signaledValue, 1), timeout, timedOut);
|
||||
if (signaled.empty()) {
|
||||
return false;
|
||||
}
|
||||
return (signaled[0] & 0x80000000ul) == 0;
|
||||
}
|
||||
|
||||
wpi::span<WPI_Handle> wpi::WaitForObjects(wpi::span<const WPI_Handle> handles,
|
||||
wpi::span<WPI_Handle> signaled) {
|
||||
std::span<WPI_Handle> wpi::WaitForObjects(std::span<const WPI_Handle> handles,
|
||||
std::span<WPI_Handle> signaled) {
|
||||
return WaitForObjects(handles, signaled, -1, nullptr);
|
||||
}
|
||||
|
||||
wpi::span<WPI_Handle> wpi::WaitForObjects(wpi::span<const WPI_Handle> handles,
|
||||
wpi::span<WPI_Handle> signaled,
|
||||
std::span<WPI_Handle> wpi::WaitForObjects(std::span<const WPI_Handle> handles,
|
||||
std::span<WPI_Handle> signaled,
|
||||
double timeout, bool* timedOut) {
|
||||
auto& manager = GetManager();
|
||||
if (gShutdown) {
|
||||
@@ -368,8 +368,8 @@ int WPI_WaitForObjectTimeout(WPI_Handle handle, double timeout,
|
||||
|
||||
int WPI_WaitForObjects(const WPI_Handle* handles, int handles_count,
|
||||
WPI_Handle* signaled) {
|
||||
return wpi::WaitForObjects(wpi::span(handles, handles_count),
|
||||
wpi::span(signaled, handles_count))
|
||||
return wpi::WaitForObjects(std::span(handles, handles_count),
|
||||
std::span(signaled, handles_count))
|
||||
.size();
|
||||
}
|
||||
|
||||
@@ -377,8 +377,8 @@ int WPI_WaitForObjectsTimeout(const WPI_Handle* handles, int handles_count,
|
||||
WPI_Handle* signaled, double timeout,
|
||||
int* timed_out) {
|
||||
bool timedOutBool;
|
||||
auto signaledResult = wpi::WaitForObjects(wpi::span(handles, handles_count),
|
||||
wpi::span(signaled, handles_count),
|
||||
auto signaledResult = wpi::WaitForObjects(std::span(handles, handles_count),
|
||||
std::span(signaled, handles_count),
|
||||
timeout, &timedOutBool);
|
||||
*timed_out = timedOutBool ? 1 : 0;
|
||||
return signaledResult.size();
|
||||
|
||||
@@ -247,7 +247,7 @@ Java_edu_wpi_first_util_WPIUtilJNI_waitForObjects
|
||||
JIntArrayRef handlesArr{env, handles};
|
||||
wpi::SmallVector<WPI_Handle, 8> signaledBuf;
|
||||
signaledBuf.resize(handlesArr.size());
|
||||
wpi::span<const WPI_Handle> handlesArr2{
|
||||
std::span<const WPI_Handle> handlesArr2{
|
||||
reinterpret_cast<const WPI_Handle*>(handlesArr.array().data()),
|
||||
handlesArr.size()};
|
||||
|
||||
@@ -271,7 +271,7 @@ Java_edu_wpi_first_util_WPIUtilJNI_waitForObjectsTimeout
|
||||
JIntArrayRef handlesArr{env, handles};
|
||||
wpi::SmallVector<WPI_Handle, 8> signaledBuf;
|
||||
signaledBuf.resize(handlesArr.size());
|
||||
wpi::span<const WPI_Handle> handlesArr2{
|
||||
std::span<const WPI_Handle> handlesArr2{
|
||||
reinterpret_cast<const WPI_Handle*>(handlesArr.array().data()),
|
||||
handlesArr.size()};
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include "wpi/SpanExtras.h"
|
||||
#include "wpi/raw_istream.h"
|
||||
#include "wpi/raw_ostream.h"
|
||||
#include "wpi/span.h"
|
||||
|
||||
namespace wpi {
|
||||
|
||||
@@ -98,7 +97,7 @@ bool ReadUleb128(raw_istream& is, uint64_t* ret) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::optional<uint64_t> Uleb128Reader::ReadOne(span<const uint8_t>* in) {
|
||||
std::optional<uint64_t> Uleb128Reader::ReadOne(std::span<const uint8_t>* in) {
|
||||
while (!in->empty()) {
|
||||
uint8_t byte = in->front();
|
||||
*in = wpi::drop_front(*in);
|
||||
|
||||
@@ -217,7 +217,7 @@ SHA1::SHA1() {
|
||||
}
|
||||
|
||||
void SHA1::Update(std::string_view s) {
|
||||
raw_mem_istream is(span<const char>(s.data(), s.size()));
|
||||
raw_mem_istream is(std::span<const char>(s.data(), s.size()));
|
||||
Update(is);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user