From 766616b4da039f5db0a3794fc6b9ffed80054a6e Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Mon, 24 Jun 2024 19:46:05 -0700 Subject: [PATCH] Give better error message on nonconformant constraint type --- include/trajopt/constraint/Constraint.hpp | 48 +++++++++++++++-------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/include/trajopt/constraint/Constraint.hpp b/include/trajopt/constraint/Constraint.hpp index 5180efef..0c4b875f 100644 --- a/include/trajopt/constraint/Constraint.hpp +++ b/include/trajopt/constraint/Constraint.hpp @@ -2,7 +2,8 @@ #pragma once -#include +#include +#include #include #include @@ -25,24 +26,37 @@ namespace trajopt { /** * ConstraintType concept. + * + * To make TrajoptLib support a new constraint type, do the following in this + * file: + * + * 1. Include the type's header file + * 2. Add a constraint static assert for the type + * 3. Add the type to Constraint's std::variant type list */ template -concept ConstraintType = requires(T t) { - { - // Parameters: - // - // sleipnir::OptimizationProblem& problem - // const Pose2v& pose - // const Translation2v& linearVelocity - // const sleipnir::Variable& angularVelocity - // const Translation2v& linearAcceleration - // const sleipnir::Variable& angularAcceleration - t.Apply(std::declval(), - std::declval(), std::declval(), - std::declval(), std::declval(), - std::declval()) - }; // NOLINT(readability/braces) -}; +concept ConstraintType = + requires(T self, sleipnir::OptimizationProblem& problem, const Pose2v& pose, + const Translation2v& linearVelocity, + const sleipnir::Variable& angularVelocity, + const Translation2v& linearAcceleration, + const sleipnir::Variable& angularAcceleration) { + { + self.Apply(problem, pose, linearVelocity, angularVelocity, + linearAcceleration, angularAcceleration) + } -> std::same_as; + }; + +static_assert(ConstraintType); +static_assert(ConstraintType); +static_assert(ConstraintType); +static_assert(ConstraintType); +static_assert(ConstraintType); +static_assert(ConstraintType); +static_assert(ConstraintType); +static_assert(ConstraintType); +static_assert(ConstraintType); +static_assert(ConstraintType); using Constraint = std::variant