From 80b6b4b2e631ac893227a6a3edac36e7cd355c63 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Mon, 24 Jun 2024 21:25:17 -0700 Subject: [PATCH] Give better error message on nonconformant constraint type (#213) --- 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