mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-05 03:21:42 +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:
@@ -74,7 +74,7 @@ static std::vector<int> FromJavaBooleanArray(JNIEnv* env, jbooleanArray jarr) {
|
||||
if (!ref) {
|
||||
return {};
|
||||
}
|
||||
wpi::span<const jboolean> elements{ref};
|
||||
std::span<const jboolean> elements{ref};
|
||||
size_t len = elements.size();
|
||||
std::vector<int> arr;
|
||||
arr.reserve(len);
|
||||
@@ -118,7 +118,7 @@ static jobject MakeJObject(JNIEnv* env, nt::Timestamped{{ t.TypeName }} value) {
|
||||
{% endfor %}
|
||||
{%- for t in types %}
|
||||
static jobjectArray MakeJObject(JNIEnv* env,
|
||||
wpi::span<const nt::Timestamped{{ t.TypeName }}> arr) {
|
||||
std::span<const nt::Timestamped{{ t.TypeName }}> arr) {
|
||||
jobjectArray jarr =
|
||||
env->NewObjectArray(arr.size(), timestamped{{ t.TypeName }}Cls, nullptr);
|
||||
if (!jarr) {
|
||||
@@ -133,7 +133,7 @@ static jobjectArray MakeJObject(JNIEnv* env,
|
||||
{% endfor %}
|
||||
{%- for t in types %}
|
||||
{%- if t.jni.ToJavaArray == "MakeJObjectArray" %}
|
||||
static jobjectArray MakeJObjectArray(JNIEnv* env, wpi::span<const {{ t.cpp.ValueType }}> arr) {
|
||||
static jobjectArray MakeJObjectArray(JNIEnv* env, std::span<const {{ t.cpp.ValueType }}> arr) {
|
||||
jobjectArray jarr =
|
||||
env->NewObjectArray(arr.size(), {{ t.jni.jtype }}Cls, nullptr);
|
||||
if (!jarr) {
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
using namespace nt;
|
||||
|
||||
template <typename T>
|
||||
static inline wpi::span<const T> ConvertFromC(const T* arr, size_t size) {
|
||||
static inline std::span<const T> ConvertFromC(const T* arr, size_t size) {
|
||||
return {arr, size};
|
||||
}
|
||||
|
||||
|
||||
@@ -7,11 +7,10 @@
|
||||
#include <stdint.h>
|
||||
|
||||
{{ cpp.INCLUDES }}
|
||||
#include <span>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "networktables/Topic.h"
|
||||
|
||||
namespace wpi {
|
||||
@@ -312,7 +311,7 @@ class {{ TypeName }}Topic final : public Topic {
|
||||
[[nodiscard]]
|
||||
SubscriberType Subscribe(
|
||||
{% if not TypeString %}std::string_view typeString, {% endif %}ParamType defaultValue,
|
||||
wpi::span<const PubSubOption> options = {});
|
||||
std::span<const PubSubOption> options = {});
|
||||
{%- if TypeString %}
|
||||
/**
|
||||
* Create a new subscriber to the topic, with specific type string.
|
||||
@@ -333,7 +332,7 @@ class {{ TypeName }}Topic final : public Topic {
|
||||
[[nodiscard]]
|
||||
SubscriberType SubscribeEx(
|
||||
std::string_view typeString, ParamType defaultValue,
|
||||
wpi::span<const PubSubOption> options = {});
|
||||
std::span<const PubSubOption> options = {});
|
||||
{% endif %}
|
||||
/**
|
||||
* Create a new publisher to the topic.
|
||||
@@ -354,7 +353,7 @@ class {{ TypeName }}Topic final : public Topic {
|
||||
* @return publisher
|
||||
*/
|
||||
[[nodiscard]]
|
||||
PublisherType Publish({% if not TypeString %}std::string_view typeString, {% endif %}wpi::span<const PubSubOption> options = {});
|
||||
PublisherType Publish({% if not TypeString %}std::string_view typeString, {% endif %}std::span<const PubSubOption> options = {});
|
||||
|
||||
/**
|
||||
* Create a new publisher to the topic, with type string and initial
|
||||
@@ -376,7 +375,7 @@ class {{ TypeName }}Topic final : public Topic {
|
||||
*/
|
||||
[[nodiscard]]
|
||||
PublisherType PublishEx(std::string_view typeString,
|
||||
const wpi::json& properties, wpi::span<const PubSubOption> options = {});
|
||||
const wpi::json& properties, std::span<const PubSubOption> options = {});
|
||||
|
||||
/**
|
||||
* Create a new entry for the topic.
|
||||
@@ -403,7 +402,7 @@ class {{ TypeName }}Topic final : public Topic {
|
||||
*/
|
||||
[[nodiscard]]
|
||||
EntryType GetEntry({% if not TypeString %}std::string_view typeString, {% endif %}ParamType defaultValue,
|
||||
wpi::span<const PubSubOption> options = {});
|
||||
std::span<const PubSubOption> options = {});
|
||||
{%- if TypeString %}
|
||||
/**
|
||||
* Create a new entry for the topic, with specific type string.
|
||||
@@ -428,7 +427,7 @@ class {{ TypeName }}Topic final : public Topic {
|
||||
*/
|
||||
[[nodiscard]]
|
||||
EntryType GetEntryEx(std::string_view typeString, ParamType defaultValue,
|
||||
wpi::span<const PubSubOption> options = {});
|
||||
std::span<const PubSubOption> options = {});
|
||||
{% endif %}
|
||||
};
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ inline void {{ TypeName }}Entry::Unpublish() {
|
||||
|
||||
inline {{ TypeName }}Subscriber {{ TypeName }}Topic::Subscribe(
|
||||
{% if not TypeString %}std::string_view typeString, {% endif %}{{ cpp.ParamType }} defaultValue,
|
||||
wpi::span<const PubSubOption> options) {
|
||||
std::span<const PubSubOption> options) {
|
||||
return {{ TypeName }}Subscriber{
|
||||
::nt::Subscribe(m_handle, NT_{{ cpp.TYPE_NAME }}, {{ TypeString|default('typeString') }}, options),
|
||||
defaultValue};
|
||||
@@ -97,28 +97,28 @@ inline {{ TypeName }}Subscriber {{ TypeName }}Topic::Subscribe(
|
||||
{%- if TypeString %}
|
||||
inline {{ TypeName }}Subscriber {{ TypeName }}Topic::SubscribeEx(
|
||||
std::string_view typeString, {{ cpp.ParamType }} defaultValue,
|
||||
wpi::span<const PubSubOption> options) {
|
||||
std::span<const PubSubOption> options) {
|
||||
return {{ TypeName }}Subscriber{
|
||||
::nt::Subscribe(m_handle, NT_{{ cpp.TYPE_NAME }}, typeString, options),
|
||||
defaultValue};
|
||||
}
|
||||
{% endif %}
|
||||
inline {{ TypeName }}Publisher {{ TypeName }}Topic::Publish(
|
||||
{% if not TypeString %}std::string_view typeString, {% endif %}wpi::span<const PubSubOption> options) {
|
||||
{% if not TypeString %}std::string_view typeString, {% endif %}std::span<const PubSubOption> options) {
|
||||
return {{ TypeName }}Publisher{
|
||||
::nt::Publish(m_handle, NT_{{ cpp.TYPE_NAME }}, {{ TypeString|default('typeString') }}, options)};
|
||||
}
|
||||
|
||||
inline {{ TypeName }}Publisher {{ TypeName }}Topic::PublishEx(
|
||||
std::string_view typeString,
|
||||
const wpi::json& properties, wpi::span<const PubSubOption> options) {
|
||||
const wpi::json& properties, std::span<const PubSubOption> options) {
|
||||
return {{ TypeName }}Publisher{
|
||||
::nt::PublishEx(m_handle, NT_{{ cpp.TYPE_NAME }}, typeString, properties, options)};
|
||||
}
|
||||
|
||||
inline {{ TypeName }}Entry {{ TypeName }}Topic::GetEntry(
|
||||
{% if not TypeString %}std::string_view typeString, {% endif %}{{ cpp.ParamType }} defaultValue,
|
||||
wpi::span<const PubSubOption> options) {
|
||||
std::span<const PubSubOption> options) {
|
||||
return {{ TypeName }}Entry{
|
||||
::nt::GetEntry(m_handle, NT_{{ cpp.TYPE_NAME }}, {{ TypeString|default('typeString') }}, options),
|
||||
defaultValue};
|
||||
@@ -126,7 +126,7 @@ inline {{ TypeName }}Entry {{ TypeName }}Topic::GetEntry(
|
||||
{%- if TypeString %}
|
||||
inline {{ TypeName }}Entry {{ TypeName }}Topic::GetEntryEx(
|
||||
std::string_view typeString, {{ cpp.ParamType }} defaultValue,
|
||||
wpi::span<const PubSubOption> options) {
|
||||
std::span<const PubSubOption> options) {
|
||||
return {{ TypeName }}Entry{
|
||||
::nt::GetEntry(m_handle, NT_{{ cpp.TYPE_NAME }}, typeString, options),
|
||||
defaultValue};
|
||||
|
||||
@@ -6,13 +6,12 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "ntcore_c.h"
|
||||
|
||||
namespace wpi {
|
||||
|
||||
@@ -167,11 +167,11 @@
|
||||
},
|
||||
"cpp": {
|
||||
"ValueType": "std::vector<uint8_t>",
|
||||
"ParamType": "wpi::span<const uint8_t>",
|
||||
"ParamType": "std::span<const uint8_t>",
|
||||
"DefaultValueCopy": "defaultValue.begin(), defaultValue.end()",
|
||||
"TYPE_NAME": "RAW",
|
||||
"INCLUDES": "#include <utility>",
|
||||
"SmallRetType": "wpi::span<uint8_t>",
|
||||
"SmallRetType": "std::span<uint8_t>",
|
||||
"SmallElemType": "uint8_t"
|
||||
},
|
||||
"java": {
|
||||
@@ -201,11 +201,11 @@
|
||||
},
|
||||
"cpp": {
|
||||
"ValueType": "std::vector<int>",
|
||||
"ParamType": "wpi::span<const int>",
|
||||
"ParamType": "std::span<const int>",
|
||||
"DefaultValueCopy": "defaultValue.begin(), defaultValue.end()",
|
||||
"TYPE_NAME": "BOOLEAN_ARRAY",
|
||||
"INCLUDES": "#include <utility>",
|
||||
"SmallRetType": "wpi::span<int>",
|
||||
"SmallRetType": "std::span<int>",
|
||||
"SmallElemType": "int"
|
||||
},
|
||||
"java": {
|
||||
@@ -236,11 +236,11 @@
|
||||
},
|
||||
"cpp": {
|
||||
"ValueType": "std::vector<int64_t>",
|
||||
"ParamType": "wpi::span<const int64_t>",
|
||||
"ParamType": "std::span<const int64_t>",
|
||||
"DefaultValueCopy": "defaultValue.begin(), defaultValue.end()",
|
||||
"TYPE_NAME": "INTEGER_ARRAY",
|
||||
"INCLUDES": "#include <utility>",
|
||||
"SmallRetType": "wpi::span<int64_t>",
|
||||
"SmallRetType": "std::span<int64_t>",
|
||||
"SmallElemType": "int64_t"
|
||||
},
|
||||
"java": {
|
||||
@@ -271,11 +271,11 @@
|
||||
},
|
||||
"cpp": {
|
||||
"ValueType": "std::vector<float>",
|
||||
"ParamType": "wpi::span<const float>",
|
||||
"ParamType": "std::span<const float>",
|
||||
"DefaultValueCopy": "defaultValue.begin(), defaultValue.end()",
|
||||
"TYPE_NAME": "FLOAT_ARRAY",
|
||||
"INCLUDES": "#include <utility>",
|
||||
"SmallRetType": "wpi::span<float>",
|
||||
"SmallRetType": "std::span<float>",
|
||||
"SmallElemType": "float"
|
||||
},
|
||||
"java": {
|
||||
@@ -306,11 +306,11 @@
|
||||
},
|
||||
"cpp": {
|
||||
"ValueType": "std::vector<double>",
|
||||
"ParamType": "wpi::span<const double>",
|
||||
"ParamType": "std::span<const double>",
|
||||
"DefaultValueCopy": "defaultValue.begin(), defaultValue.end()",
|
||||
"TYPE_NAME": "DOUBLE_ARRAY",
|
||||
"INCLUDES": "#include <utility>",
|
||||
"SmallRetType": "wpi::span<double>",
|
||||
"SmallRetType": "std::span<double>",
|
||||
"SmallElemType": "double"
|
||||
},
|
||||
"java": {
|
||||
@@ -341,7 +341,7 @@
|
||||
},
|
||||
"cpp": {
|
||||
"ValueType": "std::vector<std::string>",
|
||||
"ParamType": "wpi::span<const std::string>",
|
||||
"ParamType": "std::span<const std::string>",
|
||||
"DefaultValueCopy": "defaultValue.begin(), defaultValue.end()",
|
||||
"TYPE_NAME": "STRING_ARRAY",
|
||||
"INCLUDES": "#include <utility>"
|
||||
|
||||
Reference in New Issue
Block a user