Skip to content
This repository has been archived by the owner on Jul 8, 2024. It is now read-only.

Commit

Permalink
Replace _append_variant() with variant_cat_t (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
calcmogul authored Jun 21, 2024
1 parent 168d781 commit c822702
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Constraint, AngularVelocityConstraint,
DifferentialTangentialVelocityConstraint,
DifferentialCentripetalAccelerationConstraint>;

} // namespace trajopt
8 changes: 4 additions & 4 deletions include/trajopt/constraint/holonomic/HolonomicConstraint.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Constraint, AngularVelocityConstraint,
HolonomicVelocityConstraint, PointAtConstraint>;

} // namespace trajopt
36 changes: 0 additions & 36 deletions include/trajopt/util/AppendVariant.h

This file was deleted.

32 changes: 32 additions & 0 deletions include/trajopt/util/VariantCat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) TrajoptLib contributors

#pragma once

#include <variant>

namespace trajopt {

namespace detail {

//! @cond Doxygen_Suppress

template <typename Variant, typename... Args>
struct variant_cat;

template <typename... Args0, typename... Args1>
struct variant_cat<std::variant<Args0...>, Args1...> {
using type = std::variant<Args0..., Args1...>;
};

//! @endcond

} // namespace detail

/**
* Defines a new variant type that appends the types Args... to the variant type
* Variant.
*/
template <typename Variant, typename... Args>
using variant_cat_t = typename detail::variant_cat<Variant, Args...>::type;

} // namespace trajopt

0 comments on commit c822702

Please sign in to comment.