mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
Replace SFINAE with concepts (#5361)
Concepts are cleaner to use and result in much better error messages for incorrect template use.
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <numbers>
|
||||
#include <type_traits>
|
||||
|
||||
#include <wpi/SymbolExports.h>
|
||||
|
||||
@@ -25,12 +26,11 @@ namespace frc {
|
||||
* be infinite.
|
||||
* @return The value after the deadband is applied.
|
||||
*/
|
||||
template <typename T,
|
||||
typename = std::enable_if_t<std::disjunction_v<
|
||||
std::is_floating_point<T>, units::traits::is_unit_t<T>>>>
|
||||
template <typename T>
|
||||
requires std::is_arithmetic_v<T> || units::traits::is_unit_t_v<T>
|
||||
T ApplyDeadband(T value, T deadband, T maxMagnitude = T{1.0}) {
|
||||
T magnitude;
|
||||
if constexpr (std::is_floating_point_v<T>) {
|
||||
if constexpr (std::is_arithmetic_v<T>) {
|
||||
magnitude = std::abs(value);
|
||||
} else {
|
||||
magnitude = units::math::abs(value);
|
||||
|
||||
Reference in New Issue
Block a user