mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +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:
@@ -8,6 +8,8 @@
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include <wpi/concepts.h>
|
||||
|
||||
#include "frc2/command/CommandBase.h"
|
||||
#include "frc2/command/CommandHelper.h"
|
||||
|
||||
@@ -35,16 +37,14 @@ class ConditionalCommand
|
||||
* @param onFalse the command to run if the condition is false
|
||||
* @param condition the condition to determine which command to run
|
||||
*/
|
||||
template <class T1, class T2,
|
||||
typename = std::enable_if_t<
|
||||
std::is_base_of_v<Command, std::remove_reference_t<T1>>>,
|
||||
typename = std::enable_if_t<
|
||||
std::is_base_of_v<Command, std::remove_reference_t<T2>>>>
|
||||
ConditionalCommand(T1&& onTrue, T2&& onFalse, std::function<bool()> condition)
|
||||
: ConditionalCommand(std::make_unique<std::remove_reference_t<T1>>(
|
||||
std::forward<T1>(onTrue)),
|
||||
std::make_unique<std::remove_reference_t<T2>>(
|
||||
std::forward<T2>(onFalse)),
|
||||
template <std::derived_from<Command> Command1,
|
||||
std::derived_from<Command> Command2>
|
||||
ConditionalCommand(Command1&& onTrue, Command2&& onFalse,
|
||||
std::function<bool()> condition)
|
||||
: ConditionalCommand(std::make_unique<std::decay_t<Command1>>(
|
||||
std::forward<Command1>(onTrue)),
|
||||
std::make_unique<std::decay_t<Command2>>(
|
||||
std::forward<Command2>(onFalse)),
|
||||
condition) {}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user