mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-30 02:31:44 +00:00
[wpimath] Make controllers and some trajectory classes constexpr (#7343)
This commit is contained in:
@@ -15,7 +15,7 @@ class SendableBuilder;
|
||||
*/
|
||||
class WPILIB_DLLEXPORT Sendable {
|
||||
public:
|
||||
virtual ~Sendable() = default;
|
||||
constexpr virtual ~Sendable() = default;
|
||||
|
||||
/**
|
||||
* Initializes this Sendable object.
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user