mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
wpiutil: Replace LLVM Optional with C++17-compatible optional
Imported from https://github.com/akrzemi1/Optional with minor changes: - Compiler conditional simplifications (we only use recent versions) - Move from std::experimental to wpi namespace - Change tests to integrate with Google Test Update LLVM use cases.
This commit is contained in:
@@ -132,10 +132,10 @@ void wpi::write_integer(raw_ostream &S, long long N, size_t MinDigits,
|
||||
}
|
||||
|
||||
void wpi::write_hex(raw_ostream &S, uint64_t N, HexPrintStyle Style,
|
||||
Optional<size_t> Width) {
|
||||
optional<size_t> Width) {
|
||||
const size_t kMaxWidth = 128u;
|
||||
|
||||
size_t W = std::min(kMaxWidth, Width.getValueOr(0u));
|
||||
size_t W = std::min(kMaxWidth, Width.value_or(0u));
|
||||
|
||||
unsigned Nibbles = (64 - countLeadingZeros(N) + 3) / 4;
|
||||
bool Prefix = (Style == HexPrintStyle::PrefixLower ||
|
||||
@@ -162,8 +162,8 @@ void wpi::write_hex(raw_ostream &S, uint64_t N, HexPrintStyle Style,
|
||||
}
|
||||
|
||||
void wpi::write_double(raw_ostream &S, double N, FloatStyle Style,
|
||||
Optional<size_t> Precision) {
|
||||
size_t Prec = Precision.getValueOr(getDefaultPrecision(Style));
|
||||
optional<size_t> Precision) {
|
||||
size_t Prec = Precision.value_or(getDefaultPrecision(Style));
|
||||
|
||||
if (std::isnan(N)) {
|
||||
S << "nan";
|
||||
|
||||
@@ -372,7 +372,7 @@ raw_ostream &raw_ostream::operator<<(const FormattedBytes &FB) {
|
||||
const size_t Size = Bytes.size();
|
||||
HexPrintStyle HPS = FB.Upper ? HexPrintStyle::Upper : HexPrintStyle::Lower;
|
||||
uint64_t OffsetWidth = 0;
|
||||
if (FB.FirstByteOffset.hasValue()) {
|
||||
if (FB.FirstByteOffset.has_value()) {
|
||||
// Figure out how many nibbles are needed to print the largest offset
|
||||
// represented by this data set, so that we can align the offset field
|
||||
// to the right width.
|
||||
@@ -392,8 +392,8 @@ raw_ostream &raw_ostream::operator<<(const FormattedBytes &FB) {
|
||||
while (!Bytes.empty()) {
|
||||
indent(FB.IndentLevel);
|
||||
|
||||
if (FB.FirstByteOffset.hasValue()) {
|
||||
uint64_t Offset = FB.FirstByteOffset.getValue();
|
||||
if (FB.FirstByteOffset.has_value()) {
|
||||
uint64_t Offset = FB.FirstByteOffset.value();
|
||||
wpi::write_hex(*this, Offset + LineIndex, HPS, OffsetWidth);
|
||||
*this << ": ";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user