Use C++23 std::expected (#8823)

This commit is contained in:
Gold856
2026-07-02 02:10:52 -04:00
committed by GitHub
parent 1299abc173
commit 4e7dd4cfbb
37 changed files with 133 additions and 2709 deletions

View File

@@ -33,7 +33,7 @@ jobs:
container: wpilib/debian-base:trixie
steps:
- name: Install Dependencies
run: sudo apt-get update && sudo apt-get install -y libopencv-dev clang-18 ninja-build avahi-daemon
run: sudo apt-get update && sudo apt-get install -y libopencv-dev clang-19 ninja-build avahi-daemon
- name: Install sccache
uses: mozilla-actions/sccache-action@v0.0.10
@@ -41,7 +41,7 @@ jobs:
- uses: actions/checkout@v6
- name: configure
run: mkdir build && cd build && cmake -G Ninja -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache -DCMAKE_C_COMPILER:FILEPATH=/usr/bin/clang-18 -DCMAKE_CXX_COMPILER:FILEPATH=/usr/bin/clang++-18 ${{ matrix.cmake-flags }} ..
run: mkdir build && cd build && cmake -G Ninja -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache -DCMAKE_C_COMPILER:FILEPATH=/usr/bin/clang-19 -DCMAKE_CXX_COMPILER:FILEPATH=/usr/bin/clang++-19 ${{ matrix.cmake-flags }} ..
env:
SCCACHE_WEBDAV_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
SCCACHE_WEBDAV_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}

View File

@@ -60,12 +60,6 @@ jobs:
./eigen.py clone
./eigen.py copy-src
./eigen.py format-patch
- name: Run expected.py
run: |
cd upstream_utils
./expected.py clone
./expected.py copy-src
./expected.py format-patch
- name: Run fmt.py
run: |
cd upstream_utils

View File

@@ -21,7 +21,6 @@ paths = [
"wpiutil/src/main/native/include",
"wpiutil/src/main/native/thirdparty/argparse/include",
"wpiutil/src/main/native/thirdparty/debugging/include",
"wpiutil/src/main/native/thirdparty/expected/include",
"wpiutil/src/main/native/thirdparty/fmtlib/include",
"wpiutil/src/main/native/thirdparty/json/include",
"wpiutil/src/main/native/thirdparty/llvm/include",

View File

@@ -5,12 +5,12 @@
#include "wpi/glass/support/ExpressionParser.hpp"
#include <cmath>
#include <expected>
#include <stack>
#include <string>
#include <type_traits>
#include "wpi/util/StringExtras.hpp"
#include "wpi/util/expected"
namespace wpi::glass::expression {
@@ -219,17 +219,17 @@ std::optional<double> ValueFromString(std::string_view str) {
}
template <typename V>
wpi::util::expected<V, std::string> EvalAll(std::stack<Operator>& operStack,
std::stack<V>& valStack) {
std::expected<V, std::string> EvalAll(std::stack<Operator>& operStack,
std::stack<V>& valStack) {
while (!operStack.empty()) {
if (valStack.size() < 2) {
return wpi::util::unexpected("Missing operand");
return std::unexpected("Missing operand");
}
ApplyOperator<V>(valStack, operStack.top());
operStack.pop();
}
if (valStack.empty()) {
return wpi::util::unexpected("No value");
return std::unexpected("No value");
}
// Intentionally leaves the result value on top of valStack so unmatched
@@ -238,7 +238,7 @@ wpi::util::expected<V, std::string> EvalAll(std::stack<Operator>& operStack,
}
template <typename V>
wpi::util::expected<V, std::string> ParseExpr(Lexer& lexer, bool insideParen) {
std::expected<V, std::string> ParseExpr(Lexer& lexer, bool insideParen) {
std::stack<Operator> operStack;
std::stack<V> valStack;
@@ -257,7 +257,7 @@ wpi::util::expected<V, std::string> ParseExpr(Lexer& lexer, bool insideParen) {
// is probably not what the user intended in this case, so give them an
// error.
if (prevType == TokenType::Number) {
return wpi::util::unexpected("Missing operator");
return std::unexpected("Missing operator");
}
// Implicit multiplication. Ex: "2(4 + 5)"
@@ -270,7 +270,7 @@ wpi::util::expected<V, std::string> ParseExpr(Lexer& lexer, bool insideParen) {
if (value) {
valStack.push(value.value());
} else {
return wpi::util::unexpected("Invalid number");
return std::unexpected("Invalid number");
}
break;
@@ -282,7 +282,7 @@ wpi::util::expected<V, std::string> ParseExpr(Lexer& lexer, bool insideParen) {
operStack.push(Operator::Multiply);
}
wpi::util::expected<V, std::string> result = ParseExpr<V>(lexer, true);
std::expected<V, std::string> result = ParseExpr<V>(lexer, true);
if (!result) {
return result;
}
@@ -293,7 +293,7 @@ wpi::util::expected<V, std::string> ParseExpr(Lexer& lexer, bool insideParen) {
if (nextType == TokenType::End) {
goto end; // Act as if closed at end of expression
}
return wpi::util::unexpected("Expected )");
return std::unexpected("Expected )");
}
break;
}
@@ -307,8 +307,7 @@ wpi::util::expected<V, std::string> ParseExpr(Lexer& lexer, bool insideParen) {
// Acts as if there was open paren at start of expression. EvalAll will
// clear both stacks, and leave the result value on top of valStack.
// This makes sure everything inside the parentheses is evaluated first
wpi::util::expected<V, std::string> result =
EvalAll<V>(operStack, valStack);
std::expected<V, std::string> result = EvalAll<V>(operStack, valStack);
if (!result) {
return result;
}
@@ -316,8 +315,8 @@ wpi::util::expected<V, std::string> ParseExpr(Lexer& lexer, bool insideParen) {
}
case TokenType::Error:
return wpi::util::unexpected(std::string("Unexpected character: ")
.append(token.str, token.strLen));
return std::unexpected(std::string("Unexpected character: ")
.append(token.str, token.strLen));
default:
Operator op = GetOperator(token.type);
@@ -343,7 +342,7 @@ wpi::util::expected<V, std::string> ParseExpr(Lexer& lexer, bool insideParen) {
precedence < prevPrecedence) {
operStack.pop();
if (valStack.size() < 2) {
return wpi::util::unexpected("Missing operand");
return std::unexpected("Missing operand");
}
ApplyOperator<V>(valStack, prevOp);
} else {
@@ -364,13 +363,13 @@ end:
// expr is null-terminated string, as ImGui::inputText() uses
template <typename V>
wpi::util::expected<V, std::string> TryParseExpr(const char* expr) {
std::expected<V, std::string> TryParseExpr(const char* expr) {
Lexer lexer(expr, std::is_integral_v<V>);
return ParseExpr<V>(lexer, false);
}
template wpi::util::expected<double, std::string> TryParseExpr(const char*);
template wpi::util::expected<float, std::string> TryParseExpr(const char*);
template wpi::util::expected<int64_t, std::string> TryParseExpr(const char*);
template std::expected<double, std::string> TryParseExpr(const char*);
template std::expected<float, std::string> TryParseExpr(const char*);
template std::expected<int64_t, std::string> TryParseExpr(const char*);
} // namespace wpi::glass::expression

View File

@@ -6,20 +6,16 @@
#include <stdint.h>
#include <expected>
#include <string>
#include "wpi/util/expected"
namespace wpi::glass::expression {
template <typename V>
wpi::util::expected<V, std::string> TryParseExpr(const char* expr);
std::expected<V, std::string> TryParseExpr(const char* expr);
extern template wpi::util::expected<double, std::string> TryParseExpr(
const char*);
extern template wpi::util::expected<float, std::string> TryParseExpr(
const char*);
extern template wpi::util::expected<int64_t, std::string> TryParseExpr(
const char*);
extern template std::expected<double, std::string> TryParseExpr(const char*);
extern template std::expected<float, std::string> TryParseExpr(const char*);
extern template std::expected<int64_t, std::string> TryParseExpr(const char*);
} // namespace wpi::glass::expression

View File

@@ -7,6 +7,7 @@
#include <stdint.h>
#include <array>
#include <expected>
#include <memory>
#include <string_view>
#include <utility>
@@ -15,7 +16,6 @@
#include "wpi/hal/Errors.h"
#include "wpi/hal/Types.h"
#include "wpi/hal/handles/HandlesInternal.hpp"
#include "wpi/util/expected"
#include "wpi/util/mutex.hpp"
namespace wpi::hal {
@@ -41,7 +41,7 @@ class DigitalHandleResource : public HandleBase {
DigitalHandleResource(const DigitalHandleResource&) = delete;
DigitalHandleResource& operator=(const DigitalHandleResource&) = delete;
wpi::util::expected<std::pair<THandle, std::shared_ptr<TStruct>>, HAL_Status>
std::expected<std::pair<THandle, std::shared_ptr<TStruct>>, HAL_Status>
Allocate(int16_t index, HAL_HandleEnum enumValue, std::string_view name);
int16_t GetIndex(THandle handle, HAL_HandleEnum enumValue) {
return getHandleTypedIndex(handle, enumValue, m_version);
@@ -56,23 +56,23 @@ class DigitalHandleResource : public HandleBase {
};
template <typename THandle, typename TStruct, int16_t size>
wpi::util::expected<std::pair<THandle, std::shared_ptr<TStruct>>, HAL_Status>
std::expected<std::pair<THandle, std::shared_ptr<TStruct>>, HAL_Status>
DigitalHandleResource<THandle, TStruct, size>::Allocate(
int16_t index, HAL_HandleEnum enumValue, std::string_view name) {
// don't acquire the lock if we can fail early.
if (index < 0 || index >= size) {
return wpi::util::unexpected(MakeErrorIndexOutOfRange(
HAL_RESOURCE_OUT_OF_RANGE, name, 0, size, index));
return std::unexpected(MakeErrorIndexOutOfRange(HAL_RESOURCE_OUT_OF_RANGE,
name, 0, size, index));
}
std::scoped_lock lock(m_handleMutexes[index]);
// check for allocation, otherwise allocate and return a valid handle
if (m_structures[index] != nullptr) {
if constexpr (detail::HasPreviousAllocation<TStruct>) {
return wpi::util::unexpected(MakeErrorPreviouslyAllocated(
return std::unexpected(MakeErrorPreviouslyAllocated(
HAL_RESOURCE_IS_ALLOCATED, name, index,
m_structures[index]->previousAllocation));
} else {
return wpi::util::unexpected(MakeErrorPreviouslyAllocated(
return std::unexpected(MakeErrorPreviouslyAllocated(
HAL_RESOURCE_IS_ALLOCATED, name, index, "unknown"));
}
}

View File

@@ -7,13 +7,13 @@
#include <stdint.h>
#include <array>
#include <expected>
#include <memory>
#include "wpi/hal/ErrorHandling.hpp"
#include "wpi/hal/Errors.h"
#include "wpi/hal/Types.h"
#include "wpi/hal/handles/HandlesInternal.hpp"
#include "wpi/util/expected"
#include "wpi/util/mutex.hpp"
namespace wpi::hal {
@@ -42,9 +42,10 @@ class IndexedClassedHandleResource : public HandleBase {
IndexedClassedHandleResource& operator=(const IndexedClassedHandleResource&) =
delete;
wpi::util::expected<THandle, HAL_Status> Allocate(
int16_t index, std::shared_ptr<TStruct> toSet, std::string_view name,
int offset = 0);
std::expected<THandle, HAL_Status> Allocate(int16_t index,
std::shared_ptr<TStruct> toSet,
std::string_view name,
int offset = 0);
int16_t GetIndex(THandle handle) {
return getHandleTypedIndex(handle, enumValue, m_version);
}
@@ -59,25 +60,25 @@ class IndexedClassedHandleResource : public HandleBase {
template <typename THandle, typename TStruct, int16_t size,
HAL_HandleEnum enumValue>
wpi::util::expected<THandle, HAL_Status>
std::expected<THandle, HAL_Status>
IndexedClassedHandleResource<THandle, TStruct, size, enumValue>::Allocate(
int16_t index, std::shared_ptr<TStruct> toSet, std::string_view name,
int offset) {
// don't acquire the lock if we can fail early.
if (index < 0 || index >= size) {
return wpi::util::unexpected(
MakeErrorIndexOutOfRange(HAL_RESOURCE_OUT_OF_RANGE, name, offset,
size + offset, index + offset));
return std::unexpected(MakeErrorIndexOutOfRange(HAL_RESOURCE_OUT_OF_RANGE,
name, offset, size + offset,
index + offset));
}
std::scoped_lock lock(m_handleMutexes[index]);
// check for allocation, otherwise allocate and return a valid handle
if (m_structures[index] != nullptr) {
if constexpr (detail::HasPreviousAllocation<TStruct>) {
return wpi::util::unexpected(MakeErrorPreviouslyAllocated(
return std::unexpected(MakeErrorPreviouslyAllocated(
HAL_RESOURCE_IS_ALLOCATED, name, index + offset,
m_structures[index]->previousAllocation));
} else {
return wpi::util::unexpected(MakeErrorPreviouslyAllocated(
return std::unexpected(MakeErrorPreviouslyAllocated(
HAL_RESOURCE_IS_ALLOCATED, name, index + offset, "unknown"));
}
}

View File

@@ -7,6 +7,7 @@
#include <stdint.h>
#include <array>
#include <expected>
#include <memory>
#include <string_view>
#include <utility>
@@ -15,7 +16,6 @@
#include "wpi/hal/Errors.h"
#include "wpi/hal/Types.h"
#include "wpi/hal/handles/HandlesInternal.hpp"
#include "wpi/util/expected"
#include "wpi/util/mutex.hpp"
namespace wpi::hal {
@@ -42,7 +42,7 @@ class IndexedHandleResource : public HandleBase {
IndexedHandleResource(const IndexedHandleResource&) = delete;
IndexedHandleResource& operator=(const IndexedHandleResource&) = delete;
wpi::util::expected<std::pair<THandle, std::shared_ptr<TStruct>>, HAL_Status>
std::expected<std::pair<THandle, std::shared_ptr<TStruct>>, HAL_Status>
Allocate(int16_t index, std::string_view name, int offset = 0);
int16_t GetIndex(THandle handle) {
return getHandleTypedIndex(handle, enumValue, m_version);
@@ -58,24 +58,24 @@ class IndexedHandleResource : public HandleBase {
template <typename THandle, typename TStruct, int16_t size,
HAL_HandleEnum enumValue>
wpi::util::expected<std::pair<THandle, std::shared_ptr<TStruct>>, HAL_Status>
std::expected<std::pair<THandle, std::shared_ptr<TStruct>>, HAL_Status>
IndexedHandleResource<THandle, TStruct, size, enumValue>::Allocate(
int16_t index, std::string_view name, int offset) {
// don't acquire the lock if we can fail early.
if (index < 0 || index >= size) {
return wpi::util::unexpected(
MakeErrorIndexOutOfRange(HAL_RESOURCE_OUT_OF_RANGE, name, offset,
size + offset, index + offset));
return std::unexpected(MakeErrorIndexOutOfRange(HAL_RESOURCE_OUT_OF_RANGE,
name, offset, size + offset,
index + offset));
}
std::scoped_lock lock(m_handleMutexes[index]);
// check for allocation, otherwise allocate and return a valid handle
if (m_structures[index] != nullptr) {
if constexpr (detail::HasPreviousAllocation<TStruct>) {
return wpi::util::unexpected(MakeErrorPreviouslyAllocated(
return std::unexpected(MakeErrorPreviouslyAllocated(
HAL_RESOURCE_IS_ALLOCATED, name, index + offset,
m_structures[index]->previousAllocation));
} else {
return wpi::util::unexpected(MakeErrorPreviouslyAllocated(
return std::unexpected(MakeErrorPreviouslyAllocated(
HAL_RESOURCE_IS_ALLOCATED, name, index + offset, "unknown"));
}
}

View File

@@ -39,7 +39,6 @@ wpilib_cc_library(
"//wpiutil:wpiutil-hdrs-pkg",
"//wpiutil:json-hdrs-pkg",
"//wpiutil:mpack-hdrs-pkg",
"//wpiutil:expected-hdrs-pkg",
"//wpiutil:debugging-hdrs-pkg",
"//wpiutil:sigslot-hdrs-pkg",
"//wpiutil:nanopb-hdrs-pkg",

View File

@@ -1,41 +0,0 @@
#!/usr/bin/env python3
import shutil
from pathlib import Path
from upstream_utils import Lib
def copy_upstream_src(wpilib_root: Path):
wpiutil = wpilib_root / "wpiutil"
# Copy expected header into allwpilib
dest_filename = (
wpiutil / "src/main/native/thirdparty/expected/include/wpi/util/expected"
)
shutil.copyfile("include/tl/expected.hpp", dest_filename)
# Rename namespace from tl to wpi, and detail to detail_expected
with open(dest_filename) as f:
content = f.read()
content = content.replace("namespace tl", "namespace wpi::util")
content = content.replace("tl::", "wpi::util::")
content = content.replace("TL_", "WPI_")
content = content.replace("namespace detail", "namespace detail_expected")
content = content.replace("detail::", "detail_expected::")
with open(dest_filename, "w") as f:
f.write(content)
def main():
name = "expected"
url = "https://github.com/TartanLlama/expected"
# master on 2024-01-25
tag = "3f0ca7b19253129700a073abfa6d8638d9f7c80c"
expected = Lib(name, url, tag, copy_upstream_src)
expected.main()
if __name__ == "__main__":
main()

View File

@@ -9,7 +9,7 @@ Subject: [PATCH 15/25] Change parse to return expected with error string
2 files changed, 15 insertions(+), 13 deletions(-)
diff --git a/json.cpp b/json.cpp
index 2b4191865e84f4c160450fa8380ad578d37e1cd1..baefe6317126f95ec75fe9d9a896923d0a90e720 100644
index 2b4191865e84f4c160450fa8380ad578d37e1cd1..11f2ccde854aed19724c991b36905b221e71ae84 100644
--- a/json.cpp
+++ b/json.cpp
@@ -1258,21 +1258,22 @@ json::parse(json& j, const char*& p, const char* e, int context, int depth)
@@ -17,7 +17,7 @@ index 2b4191865e84f4c160450fa8380ad578d37e1cd1..baefe6317126f95ec75fe9d9a896923d
}
-std::pair<json::Status, json>
+wpi::util::expected<json, const char*>
+std::expected<json, const char*>
json::parse(std::string_view s)
{
- json::Status s2;
@@ -33,30 +33,30 @@ index 2b4191865e84f4c160450fa8380ad578d37e1cd1..baefe6317126f95ec75fe9d9a896923d
+ json j;
+ Status result = parse(j, p, e, 0, DEPTH);
+ if (result != success) {
+ return wpi::util::unexpected(StatusToString(result));
+ return std::unexpected(StatusToString(result));
}
- return res;
+ json j2;
+ Status s2 = parse(j2, p, e, 0, DEPTH);
+ if (s2 != absent_value) {
+ return wpi::util::unexpected(StatusToString(trailing_content));
+ return std::unexpected(StatusToString(trailing_content));
+ }
+ return j;
}
const char*
diff --git a/json.h b/json.h
index 1c0dc26a460e17dab44f13d62059cf6e69f355c9..d2962c322678b0dd664707f34151094fec90d281 100644
index 1c0dc26a460e17dab44f13d62059cf6e69f355c9..1553eecb7251d509622ab00a4ade4a672252845e 100644
--- a/json.h
+++ b/json.h
@@ -22,6 +22,7 @@
@@ -17,6 +17,7 @@
#pragma once
+#include <expected>
#include <string>
#include <string_view>
#include <vector>
#include "wpi/util/StringMap.hpp"
+#include "wpi/util/expected"
namespace wpi::util {
@@ -43,6 +44,7 @@ class json
Object
};
@@ -79,7 +79,7 @@ index 1c0dc26a460e17dab44f13d62059cf6e69f355c9..d2962c322678b0dd664707f34151094f
public:
- static const char* StatusToString(Status);
- static std::pair<Status, json> parse(std::string_view);
+ static wpi::util::expected<json, const char*> parse(std::string_view);
+ static std::expected<json, const char*> parse(std::string_view);
json(const json&);
json(json&&);

View File

@@ -9,7 +9,7 @@ Subject: [PATCH 16/25] Add parse_or_throw
2 files changed, 11 insertions(+)
diff --git a/json.cpp b/json.cpp
index baefe6317126f95ec75fe9d9a896923d0a90e720..49fbf92ea6e67e771f051f10b65ac795351c6f3d 100644
index 11f2ccde854aed19724c991b36905b221e71ae84..84712da562ee6b1966bae788fbf32876eaec4cef 100644
--- a/json.cpp
+++ b/json.cpp
@@ -1276,6 +1276,16 @@ json::parse(std::string_view s)
@@ -30,13 +30,13 @@ index baefe6317126f95ec75fe9d9a896923d0a90e720..49fbf92ea6e67e771f051f10b65ac795
json::StatusToString(json::Status status)
{
diff --git a/json.h b/json.h
index d2962c322678b0dd664707f34151094fec90d281..f42ba9c135cb76a1b0bc31f9e2c03b1ed7dce749 100644
index 1553eecb7251d509622ab00a4ade4a672252845e..c5f39687e68289adadb988df9cfd81c031266859 100644
--- a/json.h
+++ b/json.h
@@ -96,6 +96,7 @@ class json
public:
static wpi::util::expected<json, const char*> parse(std::string_view);
static std::expected<json, const char*> parse(std::string_view);
+ static json parse_or_throw(std::string_view);
json(const json&);

View File

@@ -9,7 +9,7 @@ Subject: [PATCH 17/25] Add operator==
2 files changed, 32 insertions(+)
diff --git a/json.cpp b/json.cpp
index 49fbf92ea6e67e771f051f10b65ac795351c6f3d..40479bc266390f015e291b737b5751522dac76ac 100644
index 84712da562ee6b1966bae788fbf32876eaec4cef..839c311017ccbb2f5ea8f85aab4965e9ce7af090 100644
--- a/json.cpp
+++ b/json.cpp
@@ -1361,4 +1361,30 @@ json::StatusToString(json::Status status)
@@ -44,7 +44,7 @@ index 49fbf92ea6e67e771f051f10b65ac795351c6f3d..40479bc266390f015e291b737b575152
+
} // namespace wpi::util
diff --git a/json.h b/json.h
index f42ba9c135cb76a1b0bc31f9e2c03b1ed7dce749..fbc3fb959f71f6acc344f26247597959807d23bb 100644
index c5f39687e68289adadb988df9cfd81c031266859..2f2bb7b3b0a265299a011e4e8011ea14065dca36 100644
--- a/json.h
+++ b/json.h
@@ -28,6 +28,7 @@ namespace wpi::util {

View File

@@ -9,7 +9,7 @@ Subject: [PATCH 18/25] Add container functions
2 files changed, 120 insertions(+)
diff --git a/json.cpp b/json.cpp
index 40479bc266390f015e291b737b5751522dac76ac..2307536b15be9aae19da4ec9370a5aa17d5150d1 100644
index 839c311017ccbb2f5ea8f85aab4965e9ce7af090..a800ce44ab28117b957a2f7507908cbd4c730de9 100644
--- a/json.cpp
+++ b/json.cpp
@@ -606,6 +606,28 @@ json::contains(std::string_view key) const
@@ -129,7 +129,7 @@ index 40479bc266390f015e291b737b5751522dac76ac..2307536b15be9aae19da4ec9370a5aa1
json::to_string() const
{
diff --git a/json.h b/json.h
index fbc3fb959f71f6acc344f26247597959807d23bb..62af49cb18b713304ad95e89c52f5cc5bbc4b626 100644
index 2f2bb7b3b0a265299a011e4e8011ea14065dca36..b478523deea8ae3d852ebe369cea8ca60fdec01d 100644
--- a/json.h
+++ b/json.h
@@ -216,6 +216,9 @@ class json

View File

@@ -8,7 +8,7 @@ Subject: [PATCH 19/25] Add to_json, from_json, and json_serializer struct
1 file changed, 65 insertions(+)
diff --git a/json.h b/json.h
index 62af49cb18b713304ad95e89c52f5cc5bbc4b626..e52435a79ee7537928ba59fb146f635fc8511bfc 100644
index b478523deea8ae3d852ebe369cea8ca60fdec01d..d77ff1ea380614c54579d26cc233aa8424734b5b 100644
--- a/json.h
+++ b/json.h
@@ -26,6 +26,35 @@

View File

@@ -8,11 +8,11 @@ Subject: [PATCH 20/25] Add array and object factory functions
1 file changed, 30 insertions(+)
diff --git a/json.h b/json.h
index e52435a79ee7537928ba59fb146f635fc8511bfc..6a52615ab3e1799ebcf51a3b5ca445b1e2e64b97 100644
index d77ff1ea380614c54579d26cc233aa8424734b5b..08796527ea948c1cd602c0ba7a7b24dd75e57046 100644
--- a/json.h
+++ b/json.h
@@ -19,6 +19,8 @@
@@ -20,6 +20,8 @@
#include <expected>
#include <string>
#include <string_view>
+#include <tuple>

View File

@@ -8,14 +8,15 @@ Subject: [PATCH 21/25] Add array constructor
1 file changed, 21 insertions(+)
diff --git a/json.h b/json.h
index 6a52615ab3e1799ebcf51a3b5ca445b1e2e64b97..ef3ea13b7cb147f0b383ff1ead496d495cfece32 100644
index 08796527ea948c1cd602c0ba7a7b24dd75e57046..2dbf2cd9f8cc150c8f1dcfa7ef7ecd523b14d6ca 100644
--- a/json.h
+++ b/json.h
@@ -17,6 +17,8 @@
@@ -17,7 +17,9 @@
#pragma once
+#include <concepts>
#include <expected>
+#include <ranges>
#include <string>
#include <string_view>

View File

@@ -9,7 +9,7 @@ Subject: [PATCH 22/25] Improve stringize and marshal and use raw_ostream
2 files changed, 131 insertions(+), 87 deletions(-)
diff --git a/json.cpp b/json.cpp
index 2307536b15be9aae19da4ec9370a5aa17d5150d1..1beec7cc30e90ab2e31bc488ee15cedf9a9f32e5 100644
index a800ce44ab28117b957a2f7507908cbd4c730de9..b4a6689c2cf501abd884db0a8588e1042d2bac12 100644
--- a/json.cpp
+++ b/json.cpp
@@ -27,6 +27,7 @@
@@ -291,7 +291,7 @@ index 2307536b15be9aae19da4ec9370a5aa17d5150d1..1beec7cc30e90ab2e31bc488ee15cedf
break;
default:
diff --git a/json.h b/json.h
index ef3ea13b7cb147f0b383ff1ead496d495cfece32..e42ee96ac8697eaf17fd9d5298e877a45a4644a0 100644
index 2dbf2cd9f8cc150c8f1dcfa7ef7ecd523b14d6ca..a6a459fcda6015c2195b0a32611fc61525d5483c 100644
--- a/json.h
+++ b/json.h
@@ -31,6 +31,7 @@

View File

@@ -8,7 +8,7 @@ Subject: [PATCH 23/25] Update include path
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/json.cpp b/json.cpp
index 1beec7cc30e90ab2e31bc488ee15cedf9a9f32e5..f8416f3723df70032d274f32cda36b4ef1c7ed90 100644
index b4a6689c2cf501abd884db0a8588e1042d2bac12..27fb732b5af7a5ded9971c767e96e3f4f79a6566 100644
--- a/json.cpp
+++ b/json.cpp
@@ -15,7 +15,7 @@

View File

@@ -10,7 +10,7 @@ Make unsigned constructors constexpr
2 files changed, 112 insertions(+), 39 deletions(-)
diff --git a/json.cpp b/json.cpp
index f8416f3723df70032d274f32cda36b4ef1c7ed90..7f23ece0e8fa09ccb5fef8226de39c55ef70efdd 100644
index 27fb732b5af7a5ded9971c767e96e3f4f79a6566..c2a897f2ffe411fb6528741de1f4ea9e1a76a056 100644
--- a/json.cpp
+++ b/json.cpp
@@ -247,28 +247,6 @@ LongToString(char* p, long long x)
@@ -218,7 +218,7 @@ index f8416f3723df70032d274f32cda36b4ef1c7ed90..7f23ece0e8fa09ccb5fef8226de39c55
return lhs.float_value == rhs.float_value;
case json::Type::Double:
diff --git a/json.h b/json.h
index e42ee96ac8697eaf17fd9d5298e877a45a4644a0..31c5ea39b67286df158a9d6e13ab5073498126b8 100644
index a6a459fcda6015c2195b0a32611fc61525d5483c..ca7d76d837c9e0bdfb92e7c1b7bfd24cc8cb5ae2 100644
--- a/json.h
+++ b/json.h
@@ -17,6 +17,7 @@
@@ -227,8 +227,8 @@ index e42ee96ac8697eaf17fd9d5298e877a45a4644a0..31c5ea39b67286df158a9d6e13ab5073
+#include <climits>
#include <concepts>
#include <expected>
#include <ranges>
#include <string>
@@ -92,6 +93,7 @@ class json
Null,
Bool,

View File

@@ -8,7 +8,7 @@ Subject: [PATCH 25/25] Make bool constructor safe
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/json.h b/json.h
index 31c5ea39b67286df158a9d6e13ab5073498126b8..2746badf92a5bb4de6c38007d8e6dcfbed5b47eb 100644
index ca7d76d837c9e0bdfb92e7c1b7bfd24cc8cb5ae2..cd9c52ba855c28bc4fd7316195bead50a709e184 100644
--- a/json.h
+++ b/json.h
@@ -167,7 +167,7 @@ class json

View File

@@ -4,6 +4,7 @@
#pragma once
#include <expected>
#include <string_view>
#include <Eigen/Cholesky>
@@ -11,7 +12,6 @@
#include <Eigen/LU>
#include "wpi/math/system/LinearSystemUtil.hpp"
#include "wpi/util/expected"
namespace wpi::math {
@@ -166,7 +166,7 @@ Eigen::Matrix<double, States, States> DARE(
* @return Solution to the DARE on success, or DAREError on failure.
*/
template <int States, int Inputs>
wpi::util::expected<Eigen::Matrix<double, States, States>, DAREError> DARE(
std::expected<Eigen::Matrix<double, States, States>, DAREError> DARE(
const Eigen::Matrix<double, States, States>& A,
const Eigen::Matrix<double, States, Inputs>& B,
const Eigen::Matrix<double, States, States>& Q,
@@ -175,20 +175,20 @@ wpi::util::expected<Eigen::Matrix<double, States, States>, DAREError> DARE(
if (checkPreconditions) {
// Require R be symmetric
if ((R - R.transpose()).norm() > 1e-10) {
return wpi::util::unexpected{DAREError::RNotSymmetric};
return std::unexpected{DAREError::RNotSymmetric};
}
}
// Require R be positive definite
auto R_llt = R.llt();
if (R_llt.info() != Eigen::Success) {
return wpi::util::unexpected{DAREError::RNotPositiveDefinite};
return std::unexpected{DAREError::RNotPositiveDefinite};
}
if (checkPreconditions) {
// Require Q be symmetric
if ((Q - Q.transpose()).norm() > 1e-10) {
return wpi::util::unexpected{DAREError::QNotSymmetric};
return std::unexpected{DAREError::QNotSymmetric};
}
// Require Q be positive semidefinite
@@ -203,12 +203,12 @@ wpi::util::expected<Eigen::Matrix<double, States, States>, DAREError> DARE(
auto Q_ldlt = Q.ldlt();
if (Q_ldlt.info() != Eigen::Success ||
(Q_ldlt.vectorD().array() < 0.0).any()) {
return wpi::util::unexpected{DAREError::QNotPositiveSemidefinite};
return std::unexpected{DAREError::QNotPositiveSemidefinite};
}
// Require (A, B) pair be stabilizable
if (!IsStabilizable<States, Inputs>(A, B)) {
return wpi::util::unexpected{DAREError::ABNotStabilizable};
return std::unexpected{DAREError::ABNotStabilizable};
}
// Require (A, C) pair be detectable where Q = CᵀC
@@ -221,7 +221,7 @@ wpi::util::expected<Eigen::Matrix<double, States, States>, DAREError> DARE(
Q_ldlt.transpositionsP();
if (!IsDetectable<States, States>(A, C)) {
return wpi::util::unexpected{DAREError::ACNotDetectable};
return std::unexpected{DAREError::ACNotDetectable};
}
}
@@ -281,7 +281,7 @@ J = Σ [uₖ] [0 R][uₖ] ΔT
@return Solution to the DARE on success, or DAREError on failure.
*/
template <int States, int Inputs>
wpi::util::expected<Eigen::Matrix<double, States, States>, DAREError> DARE(
std::expected<Eigen::Matrix<double, States, States>, DAREError> DARE(
const Eigen::Matrix<double, States, States>& A,
const Eigen::Matrix<double, States, Inputs>& B,
const Eigen::Matrix<double, States, States>& Q,
@@ -291,14 +291,14 @@ wpi::util::expected<Eigen::Matrix<double, States, States>, DAREError> DARE(
if (checkPreconditions) {
// Require R be symmetric
if ((R - R.transpose()).norm() > 1e-10) {
return wpi::util::unexpected{DAREError::RNotSymmetric};
return std::unexpected{DAREError::RNotSymmetric};
}
}
// Require R be positive definite
auto R_llt = R.llt();
if (R_llt.info() != Eigen::Success) {
return wpi::util::unexpected{DAREError::RNotPositiveDefinite};
return std::unexpected{DAREError::RNotPositiveDefinite};
}
// This is a change of variables to make the DARE that includes Q, R, and N
@@ -320,7 +320,7 @@ wpi::util::expected<Eigen::Matrix<double, States, States>, DAREError> DARE(
if (checkPreconditions) {
// Require Q be symmetric
if ((Q_2 - Q_2.transpose()).norm() > 1e-10) {
return wpi::util::unexpected{DAREError::QNotSymmetric};
return std::unexpected{DAREError::QNotSymmetric};
}
// Require Q be positive semidefinite
@@ -335,12 +335,12 @@ wpi::util::expected<Eigen::Matrix<double, States, States>, DAREError> DARE(
auto Q_ldlt = Q_2.ldlt();
if (Q_ldlt.info() != Eigen::Success ||
(Q_ldlt.vectorD().array() < 0.0).any()) {
return wpi::util::unexpected{DAREError::QNotPositiveSemidefinite};
return std::unexpected{DAREError::QNotPositiveSemidefinite};
}
// Require (A, B) pair be stabilizable
if (!IsStabilizable<States, Inputs>(A_2, B)) {
return wpi::util::unexpected{DAREError::ABNotStabilizable};
return std::unexpected{DAREError::ABNotStabilizable};
}
// Require (A, C) pair be detectable where Q = CᵀC
@@ -353,7 +353,7 @@ wpi::util::expected<Eigen::Matrix<double, States, States>, DAREError> DARE(
Q_ldlt.transpositionsP();
if (!IsDetectable<States, States>(A_2, C)) {
return wpi::util::unexpected{DAREError::ACNotDetectable};
return std::unexpected{DAREError::ACNotDetectable};
}
}

View File

@@ -4,25 +4,24 @@
#include "wpi/math/linalg/DARE.hpp"
#include <expected>
#include <Eigen/Core>
#include <Eigen/Eigenvalues>
#include <gtest/gtest.h>
#include "wpi/math/fmt/Eigen.hpp"
#include "wpi/math/linalg/EigenCore.hpp"
#include "wpi/util/expected"
#include "wpi/util/print.hpp"
// 2x1
extern template wpi::util::expected<Eigen::Matrix<double, 2, 2>,
wpi::math::DAREError>
extern template std::expected<Eigen::Matrix<double, 2, 2>, wpi::math::DAREError>
wpi::math::DARE<2, 1>(const Eigen::Matrix<double, 2, 2>& A,
const Eigen::Matrix<double, 2, 1>& B,
const Eigen::Matrix<double, 2, 2>& Q,
const Eigen::Matrix<double, 1, 1>& R,
bool checkPreconditions);
extern template wpi::util::expected<Eigen::Matrix<double, 2, 2>,
wpi::math::DAREError>
extern template std::expected<Eigen::Matrix<double, 2, 2>, wpi::math::DAREError>
wpi::math::DARE<2, 1>(const Eigen::Matrix<double, 2, 2>& A,
const Eigen::Matrix<double, 2, 1>& B,
const Eigen::Matrix<double, 2, 2>& Q,
@@ -31,15 +30,13 @@ wpi::math::DARE<2, 1>(const Eigen::Matrix<double, 2, 2>& A,
bool checkPreconditions);
// 4x1
extern template wpi::util::expected<Eigen::Matrix<double, 4, 4>,
wpi::math::DAREError>
extern template std::expected<Eigen::Matrix<double, 4, 4>, wpi::math::DAREError>
wpi::math::DARE<4, 1>(const Eigen::Matrix<double, 4, 4>& A,
const Eigen::Matrix<double, 4, 1>& B,
const Eigen::Matrix<double, 4, 4>& Q,
const Eigen::Matrix<double, 1, 1>& R,
bool checkPreconditions);
extern template wpi::util::expected<Eigen::Matrix<double, 4, 4>,
wpi::math::DAREError>
extern template std::expected<Eigen::Matrix<double, 4, 4>, wpi::math::DAREError>
wpi::math::DARE<4, 1>(const Eigen::Matrix<double, 4, 4>& A,
const Eigen::Matrix<double, 4, 1>& B,
const Eigen::Matrix<double, 4, 4>& Q,
@@ -48,15 +45,13 @@ wpi::math::DARE<4, 1>(const Eigen::Matrix<double, 4, 4>& A,
bool checkPreconditions);
// 2x2
extern template wpi::util::expected<Eigen::Matrix<double, 2, 2>,
wpi::math::DAREError>
extern template std::expected<Eigen::Matrix<double, 2, 2>, wpi::math::DAREError>
wpi::math::DARE<2, 2>(const Eigen::Matrix<double, 2, 2>& A,
const Eigen::Matrix<double, 2, 2>& B,
const Eigen::Matrix<double, 2, 2>& Q,
const Eigen::Matrix<double, 2, 2>& R,
bool checkPreconditions);
extern template wpi::util::expected<Eigen::Matrix<double, 2, 2>,
wpi::math::DAREError>
extern template std::expected<Eigen::Matrix<double, 2, 2>, wpi::math::DAREError>
wpi::math::DARE<2, 2>(const Eigen::Matrix<double, 2, 2>& A,
const Eigen::Matrix<double, 2, 2>& B,
const Eigen::Matrix<double, 2, 2>& Q,
@@ -65,15 +60,13 @@ wpi::math::DARE<2, 2>(const Eigen::Matrix<double, 2, 2>& A,
bool checkPreconditions);
// 2x3
extern template wpi::util::expected<Eigen::Matrix<double, 2, 2>,
wpi::math::DAREError>
extern template std::expected<Eigen::Matrix<double, 2, 2>, wpi::math::DAREError>
wpi::math::DARE<2, 3>(const Eigen::Matrix<double, 2, 2>& A,
const Eigen::Matrix<double, 2, 3>& B,
const Eigen::Matrix<double, 2, 2>& Q,
const Eigen::Matrix<double, 3, 3>& R,
bool checkPreconditions);
extern template wpi::util::expected<Eigen::Matrix<double, 2, 2>,
wpi::math::DAREError>
extern template std::expected<Eigen::Matrix<double, 2, 2>, wpi::math::DAREError>
wpi::math::DARE<2, 3>(const Eigen::Matrix<double, 2, 2>& A,
const Eigen::Matrix<double, 2, 3>& B,
const Eigen::Matrix<double, 2, 2>& Q,

View File

@@ -4,13 +4,13 @@
#include "wpi/math/linalg/DARE.hpp"
template wpi::util::expected<Eigen::Matrix<double, 2, 2>, wpi::math::DAREError>
template std::expected<Eigen::Matrix<double, 2, 2>, wpi::math::DAREError>
wpi::math::DARE<2, 1>(const Eigen::Matrix<double, 2, 2>& A,
const Eigen::Matrix<double, 2, 1>& B,
const Eigen::Matrix<double, 2, 2>& Q,
const Eigen::Matrix<double, 1, 1>& R,
bool checkPreconditions);
template wpi::util::expected<Eigen::Matrix<double, 2, 2>, wpi::math::DAREError>
template std::expected<Eigen::Matrix<double, 2, 2>, wpi::math::DAREError>
wpi::math::DARE<2, 1>(const Eigen::Matrix<double, 2, 2>& A,
const Eigen::Matrix<double, 2, 1>& B,
const Eigen::Matrix<double, 2, 2>& Q,

View File

@@ -4,13 +4,13 @@
#include "wpi/math/linalg/DARE.hpp"
template wpi::util::expected<Eigen::Matrix<double, 2, 2>, wpi::math::DAREError>
template std::expected<Eigen::Matrix<double, 2, 2>, wpi::math::DAREError>
wpi::math::DARE<2, 2>(const Eigen::Matrix<double, 2, 2>& A,
const Eigen::Matrix<double, 2, 2>& B,
const Eigen::Matrix<double, 2, 2>& Q,
const Eigen::Matrix<double, 2, 2>& R,
bool checkPreconditions);
template wpi::util::expected<Eigen::Matrix<double, 2, 2>, wpi::math::DAREError>
template std::expected<Eigen::Matrix<double, 2, 2>, wpi::math::DAREError>
wpi::math::DARE<2, 2>(const Eigen::Matrix<double, 2, 2>& A,
const Eigen::Matrix<double, 2, 2>& B,
const Eigen::Matrix<double, 2, 2>& Q,

View File

@@ -4,13 +4,13 @@
#include "wpi/math/linalg/DARE.hpp"
template wpi::util::expected<Eigen::Matrix<double, 2, 2>, wpi::math::DAREError>
template std::expected<Eigen::Matrix<double, 2, 2>, wpi::math::DAREError>
wpi::math::DARE<2, 3>(const Eigen::Matrix<double, 2, 2>& A,
const Eigen::Matrix<double, 2, 3>& B,
const Eigen::Matrix<double, 2, 2>& Q,
const Eigen::Matrix<double, 3, 3>& R,
bool checkPreconditions);
template wpi::util::expected<Eigen::Matrix<double, 2, 2>, wpi::math::DAREError>
template std::expected<Eigen::Matrix<double, 2, 2>, wpi::math::DAREError>
wpi::math::DARE<2, 3>(const Eigen::Matrix<double, 2, 2>& A,
const Eigen::Matrix<double, 2, 3>& B,
const Eigen::Matrix<double, 2, 2>& Q,

View File

@@ -2,16 +2,17 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "wpi/math/linalg/DARE.hpp"
#include "wpi/util/expected"
#include <expected>
template wpi::util::expected<Eigen::Matrix<double, 4, 4>, wpi::math::DAREError>
#include "wpi/math/linalg/DARE.hpp"
template std::expected<Eigen::Matrix<double, 4, 4>, wpi::math::DAREError>
wpi::math::DARE<4, 1>(const Eigen::Matrix<double, 4, 4>& A,
const Eigen::Matrix<double, 4, 1>& B,
const Eigen::Matrix<double, 4, 4>& Q,
const Eigen::Matrix<double, 1, 1>& R,
bool checkPreconditions);
template wpi::util::expected<Eigen::Matrix<double, 4, 4>, wpi::math::DAREError>
template std::expected<Eigen::Matrix<double, 4, 4>, wpi::math::DAREError>
wpi::math::DARE<4, 1>(const Eigen::Matrix<double, 4, 4>& A,
const Eigen::Matrix<double, 4, 1>& B,
const Eigen::Matrix<double, 4, 4>& Q,

View File

@@ -22,7 +22,6 @@ filegroup(
"src/main/native/thirdparty/argparse/include/**/*",
"src/main/native/thirdparty/debugging/include/**/*",
"src/main/native/thirdparty/double-conversion/include/**/*",
"src/main/native/thirdparty/expected/include/**/*",
"src/main/native/thirdparty/fmtlib/include/**/*",
"src/main/native/thirdparty/json/include/**/*",
"src/main/native/thirdparty/llvm/include/**/*",
@@ -105,12 +104,6 @@ third_party_cc_lib_helper(
visibility = ["//visibility:public"],
)
third_party_cc_lib_helper(
name = "expected",
include_root = "src/main/native/thirdparty/expected/include",
visibility = ["//visibility:public"],
)
third_party_cc_lib_helper(
name = "fmtlib",
include_root = "src/main/native/thirdparty/fmtlib/include",
@@ -189,7 +182,6 @@ wpilib_cc_library(
strip_include_prefix = "src/main/native/include",
third_party_header_only_libraries = [
":argparse",
":expected",
":sigslot",
],
third_party_libraries = [
@@ -366,7 +358,6 @@ generate_robotpy_native_wrapper_build_info(
"argparse",
"debugging",
"double-conversion",
"expected",
"fmtlib",
"json",
"llvm",

View File

@@ -93,7 +93,6 @@ install(
src/main/native/thirdparty/argparse/include/
src/main/native/thirdparty/debugging/include/
src/main/native/thirdparty/double-conversion/include/
src/main/native/thirdparty/expected/include/
src/main/native/thirdparty/json/include/
src/main/native/thirdparty/llvm/include/
src/main/native/thirdparty/mpack/include/
@@ -109,7 +108,6 @@ target_include_directories(
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/thirdparty/argparse/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/thirdparty/debugging/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/thirdparty/double-conversion/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/thirdparty/expected/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/thirdparty/json/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/thirdparty/llvm/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/thirdparty/mpack/include>

View File

@@ -48,7 +48,7 @@ ext {
include '**/*.cpp'
}
exportedHeaders {
srcDirs 'src/main/native/include', 'src/main/native/thirdparty/double-conversion/include', 'src/main/native/thirdparty/expected/include', 'src/main/native/thirdparty/llvm/include', 'src/main/native/thirdparty/json/include'
srcDirs 'src/main/native/include', 'src/main/native/thirdparty/double-conversion/include', 'src/main/native/thirdparty/llvm/include', 'src/main/native/thirdparty/json/include'
}
}
llvmCpp(CppSourceSet) {
@@ -57,7 +57,7 @@ ext {
include '**/*.cpp'
}
exportedHeaders {
srcDirs 'src/main/native/include', 'src/main/native/thirdparty/expected/include', 'src/main/native/thirdparty/fmtlib/include', 'src/main/native/thirdparty/llvm/include'
srcDirs 'src/main/native/include', 'src/main/native/thirdparty/fmtlib/include', 'src/main/native/thirdparty/llvm/include'
}
}
mpackCpp(CppSourceSet) {
@@ -156,7 +156,6 @@ cppHeadersZip {
'src/main/native/thirdparty/argparse/include',
'src/main/native/thirdparty/debugging/include',
'src/main/native/thirdparty/double-conversion/include',
'src/main/native/thirdparty/expected/include',
'src/main/native/thirdparty/fmtlib/include',
'src/main/native/thirdparty/json/include',
'src/main/native/thirdparty/llvm/include',
@@ -209,7 +208,7 @@ model {
all {
it.sources.each {
it.exportedHeaders {
srcDirs 'src/main/native/include', 'src/main/native/thirdparty/argparse/include/', 'src/main/native/thirdparty/debugging/include', 'src/main/native/thirdparty/double-conversion/include', 'src/main/native/thirdparty/expected/include', 'src/main/native/thirdparty/fmtlib/include', 'src/main/native/thirdparty/llvm/include', 'src/main/native/thirdparty/sigslot/include', 'src/main/native/thirdparty/json/include', 'src/main/native/thirdparty/mpack/include', 'src/main/native/thirdparty/nanopb/include', 'src/main/native/thirdparty/upb/include'
srcDirs 'src/main/native/include', 'src/main/native/thirdparty/argparse/include/', 'src/main/native/thirdparty/debugging/include', 'src/main/native/thirdparty/double-conversion/include', 'src/main/native/thirdparty/fmtlib/include', 'src/main/native/thirdparty/llvm/include', 'src/main/native/thirdparty/sigslot/include', 'src/main/native/thirdparty/json/include', 'src/main/native/thirdparty/mpack/include', 'src/main/native/thirdparty/nanopb/include', 'src/main/native/thirdparty/upb/include'
}
}
}

View File

@@ -12,7 +12,6 @@ def define_native_wrapper(name, pyproject_toml = None):
"src/main/native/thirdparty/argparse/include/**",
"src/main/native/thirdparty/debugging/include/**",
"src/main/native/thirdparty/double-conversion/include/**",
"src/main/native/thirdparty/expected/include/**",
"src/main/native/thirdparty/fmtlib/include/**",
"src/main/native/thirdparty/json/include/**",
"src/main/native/thirdparty/llvm/include/**",
@@ -29,7 +28,6 @@ def define_native_wrapper(name, pyproject_toml = None):
"wpiutil/src/main/native/thirdparty/argparse/include": "",
"wpiutil/src/main/native/thirdparty/debugging/include": "",
"wpiutil/src/main/native/thirdparty/double-conversion/include": "",
"wpiutil/src/main/native/thirdparty/expected/include": "",
"wpiutil/src/main/native/thirdparty/fmtlib/include": "",
"wpiutil/src/main/native/thirdparty/json/include": "",
"wpiutil/src/main/native/thirdparty/llvm/include": "",

File diff suppressed because it is too large Load Diff

View File

@@ -19,6 +19,7 @@
#include <climits>
#include <concepts>
#include <expected>
#include <ranges>
#include <string>
#include <string_view>
@@ -27,7 +28,6 @@
#include <vector>
#include "wpi/util/StringMap.hpp"
#include "wpi/util/expected"
namespace wpi::util {
@@ -153,7 +153,7 @@ class json
};
public:
static wpi::util::expected<json, const char*> parse(std::string_view);
static std::expected<json, const char*> parse(std::string_view);
static json parse_or_throw(std::string_view);
json(const json&);

View File

@@ -1435,7 +1435,7 @@ json::parse(json& j, const char*& p, const char* e, int context, int depth)
return unexpected_eof;
}
wpi::util::expected<json, const char*>
std::expected<json, const char*>
json::parse(std::string_view s)
{
const char* p = s.data();
@@ -1443,12 +1443,12 @@ json::parse(std::string_view s)
json j;
Status result = parse(j, p, e, 0, DEPTH);
if (result != success) {
return wpi::util::unexpected(StatusToString(result));
return std::unexpected(StatusToString(result));
}
json j2;
Status s2 = parse(j2, p, e, 0, DEPTH);
if (s2 != absent_value) {
return wpi::util::unexpected(StatusToString(trailing_content));
return std::unexpected(StatusToString(trailing_content));
}
return j;
}

View File

@@ -259,12 +259,12 @@ static std::unique_ptr<WritableMemoryBuffer> GetMemoryBufferForStream(
return GetMemBufferCopyImpl(buffer, bufferName, ec);
}
wpi::util::expected<std::unique_ptr<MemoryBuffer>, std::error_code>
std::expected<std::unique_ptr<MemoryBuffer>, std::error_code>
MemoryBuffer::GetFile(std::string_view filename, int64_t fileSize) {
std::error_code ec;
auto ret = GetFileAux<MemoryBuffer>(filename, ec, fileSize, fileSize, 0);
if (ec) {
return wpi::util::unexpected{ec};
return std::unexpected{ec};
}
return ret;
}

View File

@@ -24,7 +24,7 @@
#include <span>
#include <string_view>
#include <system_error>
#include "wpi/util/expected"
#include <expected>
// Duplicated from fs.h to avoid a dependency
namespace fs {
@@ -78,7 +78,7 @@ class MemoryBuffer {
/// if successful, otherwise returning null. If FileSize is specified, this
/// means that the client knows that the file exists and that it has the
/// specified size.
static wpi::util::expected<std::unique_ptr<MemoryBuffer>, std::error_code>
static std::expected<std::unique_ptr<MemoryBuffer>, std::error_code>
GetFile(std::string_view filename, int64_t fileSize = -1);
/// Read all of the specified file into a MemoryBuffer as a stream

View File

@@ -1,60 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "wpi/util/expected"
#include <initializer_list>
#include <tuple>
#include <utility>
#include <vector>
#include <gtest/gtest.h>
namespace {
struct TakesInitAndVariadic {
std::vector<int> v;
std::tuple<int, int> t;
template <class... Args>
TakesInitAndVariadic(std::initializer_list<int> l, // NOLINT
Args&&... args)
: v(l), t(std::forward<Args>(args)...) {}
};
} // namespace
TEST(ExpectedTest, Emplace) {
{
wpi::util::expected<std::unique_ptr<int>, int> e;
e.emplace(new int{42});
EXPECT_TRUE(e);
EXPECT_EQ(**e, 42);
}
{
wpi::util::expected<std::vector<int>, int> e;
e.emplace({0, 1});
EXPECT_TRUE(e);
EXPECT_EQ((*e)[0], 0);
EXPECT_EQ((*e)[1], 1);
}
{
wpi::util::expected<std::tuple<int, int>, int> e;
e.emplace(2, 3);
EXPECT_TRUE(e);
EXPECT_EQ(std::get<0>(*e), 2);
EXPECT_EQ(std::get<1>(*e), 3);
}
{
wpi::util::expected<TakesInitAndVariadic, int> e =
wpi::util::make_unexpected(0);
e.emplace({0, 1}, 2, 3);
EXPECT_TRUE(e);
EXPECT_EQ(e->v[0], 0);
EXPECT_EQ(e->v[1], 1);
EXPECT_EQ(std::get<0>(e->t), 2);
EXPECT_EQ(std::get<1>(e->t), 3);
}
}