Skip to content

Writing generic code

Jeremie Deray edited this page Dec 5, 2018 · 2 revisions

Writing generic code

All Lie group classes defined in manif have in common that they inherit from a templated base class.

Examples

Small example

#include <iostream>
#include <manif/manif.h>

using namespace manif;

template <typename Derived>
void print(const LieGroupBase<Derived>& g)
{
  std::cout << "Group degrees of freedom : " << g::DoF << std::endl;
  std::cout << "Group underlying representation vector size : " << g::RepSize << std::endl;
  std::cout << "Current values : " << g << std::endl;
}

int main()
{
  SE2d p_2d;
  print(p_2d);

  SE3d p_3d;
  print(p_3d);
}

Multiple templated arguments

#include <iostream>
#include <manif/manif.h>

using namespace manif;

template <typename DerivedA, typename DerivedB>
void ominusSquaredNorm(const LieGroupBase<DerivedA>& g0, const LieGroupBase<DerivedB>& g1)
{
  return (g0-g1).coeffs().squaredNorm();
}