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:
@@ -9,6 +9,7 @@
|
||||
#include <span>
|
||||
#include <utility>
|
||||
|
||||
#include <wpi/concepts.h>
|
||||
#include <wpi/deprecated.h>
|
||||
|
||||
#include "Trigger.h"
|
||||
@@ -65,8 +66,7 @@ class Button : public Trigger {
|
||||
* @return The trigger, for chained calls.
|
||||
* @deprecated Replace with Trigger::OnTrue()
|
||||
*/
|
||||
template <class T, typename = std::enable_if_t<std::is_base_of_v<
|
||||
Command, std::remove_reference_t<T>>>>
|
||||
template <std::derived_from<Command> T>
|
||||
WPI_DEPRECATED("Replace with Trigger#OnTrue()")
|
||||
Button WhenPressed(T&& command) {
|
||||
WhenActive(std::forward<T>(command));
|
||||
@@ -117,8 +117,7 @@ class Button : public Trigger {
|
||||
* @return The button, for chained calls.
|
||||
* @deprecated Replace with Trigger::WhileTrue(command.Repeatedly())
|
||||
*/
|
||||
template <class T, typename = std::enable_if_t<std::is_base_of_v<
|
||||
Command, std::remove_reference_t<T>>>>
|
||||
template <std::derived_from<Command> T>
|
||||
WPI_DEPRECATED("Replace with Trigger#WhileTrue(command.Repeatedly())")
|
||||
Button WhileHeld(T&& command) {
|
||||
WhileActiveContinous(std::forward<T>(command));
|
||||
@@ -169,8 +168,7 @@ class Button : public Trigger {
|
||||
* @return The button, for chained calls.
|
||||
* @deprecated Replace with Trigger::WhileTrue()
|
||||
*/
|
||||
template <class T, typename = std::enable_if_t<std::is_base_of_v<
|
||||
Command, std::remove_reference_t<T>>>>
|
||||
template <std::derived_from<Command> T>
|
||||
WPI_DEPRECATED("Replace with Trigger#WhileTrue()")
|
||||
Button WhenHeld(T&& command) {
|
||||
WhileActiveOnce(std::forward<T>(command));
|
||||
@@ -199,8 +197,7 @@ class Button : public Trigger {
|
||||
* @return The button, for chained calls.
|
||||
* @deprecated Replace with Trigger::OnFalse()
|
||||
*/
|
||||
template <class T, typename = std::enable_if_t<std::is_base_of_v<
|
||||
Command, std::remove_reference_t<T>>>>
|
||||
template <std::derived_from<Command> T>
|
||||
WPI_DEPRECATED("Replace with Trigger#OnFalse()")
|
||||
Button WhenReleased(T&& command) {
|
||||
WhenInactive(std::forward<T>(command));
|
||||
@@ -251,8 +248,7 @@ class Button : public Trigger {
|
||||
* @return The button, for chained calls.
|
||||
* @deprecated Replace with Trigger::ToggleOnTrue()
|
||||
*/
|
||||
template <class T, typename = std::enable_if_t<std::is_base_of_v<
|
||||
Command, std::remove_reference_t<T>>>>
|
||||
template <std::derived_from<Command> T>
|
||||
WPI_DEPRECATED("Replace with Trigger#ToggleOnTrue()")
|
||||
Button ToggleWhenPressed(T&& command) {
|
||||
ToggleWhenActive(std::forward<T>(command));
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <frc/event/EventLoop.h>
|
||||
#include <frc/filter/Debouncer.h>
|
||||
#include <units/time.h>
|
||||
#include <wpi/concepts.h>
|
||||
#include <wpi/deprecated.h>
|
||||
|
||||
#include "frc2/command/Command.h"
|
||||
@@ -226,12 +227,11 @@ class Trigger {
|
||||
* @return The trigger, for chained calls.
|
||||
* @deprecated Use OnTrue(Command) instead
|
||||
*/
|
||||
template <class T, typename = std::enable_if_t<std::is_base_of_v<
|
||||
Command, std::remove_reference_t<T>>>>
|
||||
template <std::derived_from<Command> T>
|
||||
WPI_DEPRECATED("Use OnTrue(Command) instead")
|
||||
Trigger WhenActive(T&& command) {
|
||||
m_loop->Bind([condition = m_condition, previous = m_condition(),
|
||||
command = std::make_unique<std::remove_reference_t<T>>(
|
||||
command = std::make_unique<std::decay_t<T>>(
|
||||
std::forward<T>(command))]() mutable {
|
||||
bool current = condition();
|
||||
|
||||
@@ -296,14 +296,13 @@ class Trigger {
|
||||
* @deprecated Use WhileTrue(Command) with RepeatCommand, or bind
|
||||
command::Schedule with IfHigh(std::function<void()>).
|
||||
*/
|
||||
template <class T, typename = std::enable_if_t<std::is_base_of_v<
|
||||
Command, std::remove_reference_t<T>>>>
|
||||
template <std::derived_from<Command> T>
|
||||
WPI_DEPRECATED(
|
||||
"Use WhileTrue(Command) with RepeatCommand, or bind command::Schedule "
|
||||
"with IfHigh(std::function<void()>).")
|
||||
Trigger WhileActiveContinous(T&& command) {
|
||||
m_loop->Bind([condition = m_condition, previous = m_condition(),
|
||||
command = std::make_unique<std::remove_reference_t<T>>(
|
||||
command = std::make_unique<std::decay_t<T>>(
|
||||
std::forward<T>(command))]() mutable {
|
||||
bool current = condition();
|
||||
|
||||
@@ -363,12 +362,11 @@ class Trigger {
|
||||
* @return The trigger, for chained calls.
|
||||
* @deprecated Use WhileTrue(Command) instead.
|
||||
*/
|
||||
template <class T, typename = std::enable_if_t<std::is_base_of_v<
|
||||
Command, std::remove_reference_t<T>>>>
|
||||
template <std::derived_from<Command> T>
|
||||
WPI_DEPRECATED("Use WhileTrue(Command) instead.")
|
||||
Trigger WhileActiveOnce(T&& command) {
|
||||
m_loop->Bind([condition = m_condition, previous = m_condition(),
|
||||
command = std::make_unique<std::remove_reference_t<T>>(
|
||||
command = std::make_unique<std::decay_t<T>>(
|
||||
std::forward<T>(command))]() mutable {
|
||||
bool current = condition();
|
||||
|
||||
@@ -405,12 +403,11 @@ class Trigger {
|
||||
* @return The trigger, for chained calls.
|
||||
* @deprecated Use OnFalse(Command) instead.
|
||||
*/
|
||||
template <class T, typename = std::enable_if_t<std::is_base_of_v<
|
||||
Command, std::remove_reference_t<T>>>>
|
||||
template <std::derived_from<Command> T>
|
||||
WPI_DEPRECATED("Use OnFalse(Command) instead.")
|
||||
Trigger WhenInactive(T&& command) {
|
||||
m_loop->Bind([condition = m_condition, previous = m_condition(),
|
||||
command = std::make_unique<std::remove_reference_t<T>>(
|
||||
command = std::make_unique<std::decay_t<T>>(
|
||||
std::forward<T>(command))]() mutable {
|
||||
bool current = condition();
|
||||
|
||||
@@ -471,12 +468,11 @@ class Trigger {
|
||||
* @return The trigger, for chained calls.
|
||||
* @deprecated Use ToggleOnTrue(Command) instead.
|
||||
*/
|
||||
template <class T, typename = std::enable_if_t<std::is_base_of_v<
|
||||
Command, std::remove_reference_t<T>>>>
|
||||
template <std::derived_from<Command> T>
|
||||
WPI_DEPRECATED("Use ToggleOnTrue(Command) instead.")
|
||||
Trigger ToggleWhenActive(T&& command) {
|
||||
m_loop->Bind([condition = m_condition, previous = m_condition(),
|
||||
command = std::make_unique<std::remove_reference_t<T>>(
|
||||
command = std::make_unique<std::decay_t<T>>(
|
||||
std::forward<T>(command))]() mutable {
|
||||
bool current = condition();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user