[wpimath] Make controllers and some trajectory classes constexpr (#7343)

This commit is contained in:
Tyler Veness
2024-11-07 13:02:11 -08:00
committed by GitHub
parent 44a45d44e2
commit a66fa339dc
71 changed files with 1512 additions and 1900 deletions

View File

@@ -15,7 +15,7 @@ class SendableBuilder;
*/
class WPILIB_DLLEXPORT Sendable {
public:
virtual ~Sendable() = default;
constexpr virtual ~Sendable() = default;
/**
* Initializes this Sendable object.

View File

@@ -4,6 +4,8 @@
#pragma once
#include <type_traits>
#include "wpi/sendable/SendableRegistry.h"
namespace wpi {
@@ -18,37 +20,43 @@ namespace wpi {
template <typename Derived>
class SendableHelper {
public:
SendableHelper(const SendableHelper& rhs) = default;
SendableHelper& operator=(const SendableHelper& rhs) = default;
constexpr SendableHelper(const SendableHelper& rhs) = default;
constexpr SendableHelper& operator=(const SendableHelper& rhs) = default;
#if !defined(_MSC_VER) && (defined(__llvm__) || __GNUC__ > 7)
// See https://bugzilla.mozilla.org/show_bug.cgi?id=1442819
__attribute__((no_sanitize("vptr")))
#endif
SendableHelper(SendableHelper&& rhs) {
// it is safe to call Move() multiple times with the same rhs
SendableRegistry::Move(static_cast<Derived*>(this),
static_cast<Derived*>(&rhs));
constexpr SendableHelper(SendableHelper&& rhs) {
if (!std::is_constant_evaluated()) {
// it is safe to call Move() multiple times with the same rhs
SendableRegistry::Move(static_cast<Derived*>(this),
static_cast<Derived*>(&rhs));
}
}
#if !defined(_MSC_VER) && (defined(__llvm__) || __GNUC__ > 7)
// See https://bugzilla.mozilla.org/show_bug.cgi?id=1442819
__attribute__((no_sanitize("vptr")))
#endif
SendableHelper&
constexpr SendableHelper&
operator=(SendableHelper&& rhs) {
// it is safe to call Move() multiple times with the same rhs
SendableRegistry::Move(static_cast<Derived*>(this),
static_cast<Derived*>(&rhs));
if (!std::is_constant_evaluated()) {
// it is safe to call Move() multiple times with the same rhs
SendableRegistry::Move(static_cast<Derived*>(this),
static_cast<Derived*>(&rhs));
}
return *this;
}
protected:
SendableHelper() = default;
constexpr SendableHelper() = default;
~SendableHelper() {
// it is safe to call Remove() multiple times with the same object
SendableRegistry::Remove(static_cast<Derived*>(this));
constexpr ~SendableHelper() {
if (!std::is_constant_evaluated()) {
// it is safe to call Remove() multiple times with the same object
SendableRegistry::Remove(static_cast<Derived*>(this));
}
}
};