#pragma once
#include <type_traits>
#include "wpi/sendable/SendableRegistry.h"
namespace wpi {
template <typename Derived>
class SendableHelper {
public:
constexpr SendableHelper(const SendableHelper& rhs) = default;
constexpr SendableHelper& operator=(const SendableHelper& rhs) = default;
#if !defined(_MSC_VER) && (defined(__llvm__) || __GNUC__ > 7)
__attribute__((no_sanitize("vptr")))
#endif
constexpr SendableHelper(SendableHelper&& rhs) {
if (!std::is_constant_evaluated()) {
SendableRegistry::Move(static_cast<Derived*>(this),
static_cast<Derived*>(&rhs));
}
}
#if !defined(_MSC_VER) && (defined(__llvm__) || __GNUC__ > 7)
__attribute__((no_sanitize("vptr")))
#endif
constexpr SendableHelper& operator=(SendableHelper&& rhs) {
if (!std::is_constant_evaluated()) {
SendableRegistry::Move(static_cast<Derived*>(this),
static_cast<Derived*>(&rhs));
}
return *this;
}
protected:
constexpr SendableHelper() = default;
constexpr ~SendableHelper() {
if (!std::is_constant_evaluated()) {
SendableRegistry::Remove(static_cast<Derived*>(this));
}
}
};
}