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:
Tyler Veness
2023-06-07 09:50:09 -07:00
committed by GitHub
parent d57d1a4598
commit 91cbcea841
42 changed files with 397 additions and 361 deletions

View File

@@ -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);