diff --git a/include/trajopt/constraint/differential/DifferentialConstraint.h b/include/trajopt/constraint/differential/DifferentialConstraint.h index 189beac8..efbd9f95 100644 --- a/include/trajopt/constraint/differential/DifferentialConstraint.h +++ b/include/trajopt/constraint/differential/DifferentialConstraint.h @@ -6,13 +6,13 @@ #include "trajopt/constraint/Constraint.h" #include "trajopt/constraint/differential/DifferentialCentripetalAccelerationConstraint.h" #include "trajopt/constraint/differential/DifferentialTangentialVelocityConstraint.h" -#include "trajopt/util/AppendVariant.h" +#include "trajopt/util/VariantCat.h" namespace trajopt { using DifferentialConstraint = - decltype(_append_variant(Constraint{}, AngularVelocityConstraint{}, - DifferentialTangentialVelocityConstraint{}, - DifferentialCentripetalAccelerationConstraint{})); + variant_cat_t; } // namespace trajopt diff --git a/include/trajopt/constraint/holonomic/HolonomicConstraint.h b/include/trajopt/constraint/holonomic/HolonomicConstraint.h index 358c632b..3fc1263a 100644 --- a/include/trajopt/constraint/holonomic/HolonomicConstraint.h +++ b/include/trajopt/constraint/holonomic/HolonomicConstraint.h @@ -6,12 +6,12 @@ #include "trajopt/constraint/Constraint.h" #include "trajopt/constraint/PointAtConstraint.h" #include "trajopt/constraint/holonomic/HolonomicVelocityConstraint.h" -#include "trajopt/util/AppendVariant.h" +#include "trajopt/util/VariantCat.h" namespace trajopt { -using HolonomicConstraint = decltype(_append_variant( - Constraint{}, AngularVelocityConstraint{}, HolonomicVelocityConstraint{}, - PointAtConstraint{})); +using HolonomicConstraint = + variant_cat_t; } // namespace trajopt diff --git a/include/trajopt/util/AppendVariant.h b/include/trajopt/util/AppendVariant.h deleted file mode 100644 index b15dc8d5..00000000 --- a/include/trajopt/util/AppendVariant.h +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) TrajoptLib contributors - -#pragma once - -#include - -/** - * @brief Generates a derived variant type including the types of a - * base variant and additional types listed. This function should not - * be evaluated. It may be used along with `decltype()`. For example: - * - * ```cpp - * std::variant myvar; // int - * decltype(_append_variant(myvar, double())) myvar2; // int, double - * myvar2 = 1; - * myvar2 = 2.0; - * ``` - * - * @tparam Vs The types of the base variant. - * @tparam Aps The types to append to the new variant type. - * @param myvar A variant of the base typ, used only for type deduction. - * @param newvals values of the new variant - * @return a default-constructed variant of the derived type. - */ -template -std::variant _append_variant( - [[maybe_unused]] std::variant myvar, - [[maybe_unused]] Aps... newvals) { - return std::variant(); -} - -template -inline std::variant _get_as_sub_vari(std::variant myvar) { - std::get<1>(myvar); - return std::variant(); -} diff --git a/include/trajopt/util/VariantCat.h b/include/trajopt/util/VariantCat.h new file mode 100644 index 00000000..f289e47a --- /dev/null +++ b/include/trajopt/util/VariantCat.h @@ -0,0 +1,32 @@ +// Copyright (c) TrajoptLib contributors + +#pragma once + +#include + +namespace trajopt { + +namespace detail { + +//! @cond Doxygen_Suppress + +template +struct variant_cat; + +template +struct variant_cat, Args1...> { + using type = std::variant; +}; + +//! @endcond + +} // namespace detail + +/** + * Defines a new variant type that appends the types Args... to the variant type + * Variant. + */ +template +using variant_cat_t = typename detail::variant_cat::type; + +} // namespace trajopt