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

@@ -10,9 +10,13 @@
#endif
#include <memory>
#include <type_traits>
#include <utility>
#include <vector>
#include <wpi/DecayedDerivedFrom.h>
#include <wpi/concepts.h>
#include "frc2/command/CommandGroupBase.h"
#include "frc2/command/CommandHelper.h"
@@ -54,15 +58,11 @@ class ParallelDeadlineGroup
* @param deadline the command that determines when the composition ends
* @param commands the commands to be executed
*/
template <class T, class... Types,
typename = std::enable_if_t<
std::is_base_of_v<Command, std::remove_reference_t<T>>>,
typename = std::enable_if_t<std::conjunction_v<
std::is_base_of<Command, std::remove_reference_t<Types>>...>>>
explicit ParallelDeadlineGroup(T&& deadline, Types&&... commands) {
SetDeadline(std::make_unique<std::remove_reference_t<T>>(
std::forward<T>(deadline)));
AddCommands(std::forward<Types>(commands)...);
template <wpi::DecayedDerivedFrom<Command> T,
wpi::DecayedDerivedFrom<Command>... Commands>
explicit ParallelDeadlineGroup(T&& deadline, Commands&&... commands) {
SetDeadline(std::make_unique<std::decay_t<T>>(std::forward<T>(deadline)));
AddCommands(std::forward<Commands>(commands)...);
}
ParallelDeadlineGroup(ParallelDeadlineGroup&& other) = default;
@@ -73,13 +73,11 @@ class ParallelDeadlineGroup
// Prevent template expansion from emulating copy ctor
ParallelDeadlineGroup(ParallelDeadlineGroup&) = delete;
template <class... Types,
typename = std::enable_if_t<std::conjunction_v<
std::is_base_of<Command, std::remove_reference_t<Types>>...>>>
void AddCommands(Types&&... commands) {
template <wpi::DecayedDerivedFrom<Command>... Commands>
void AddCommands(Commands&&... commands) {
std::vector<std::unique_ptr<Command>> foo;
((void)foo.emplace_back(std::make_unique<std::remove_reference_t<Types>>(
std::forward<Types>(commands))),
((void)foo.emplace_back(std::make_unique<std::decay_t<Commands>>(
std::forward<Commands>(commands))),
...);
AddCommands(std::move(foo));
}