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:
@@ -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"
|
||||
|
||||
@@ -50,11 +54,9 @@ class ParallelCommandGroup
|
||||
*
|
||||
* @param commands the commands to include in this composition.
|
||||
*/
|
||||
template <class... Types,
|
||||
typename = std::enable_if_t<std::conjunction_v<
|
||||
std::is_base_of<Command, std::remove_reference_t<Types>>...>>>
|
||||
explicit ParallelCommandGroup(Types&&... commands) {
|
||||
AddCommands(std::forward<Types>(commands)...);
|
||||
template <wpi::DecayedDerivedFrom<Command>... Commands>
|
||||
explicit ParallelCommandGroup(Commands&&... commands) {
|
||||
AddCommands(std::forward<Commands>(commands)...);
|
||||
}
|
||||
|
||||
ParallelCommandGroup(ParallelCommandGroup&& other) = default;
|
||||
@@ -65,13 +67,11 @@ class ParallelCommandGroup
|
||||
// Prevent template expansion from emulating copy ctor
|
||||
ParallelCommandGroup(ParallelCommandGroup&) = 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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user