From 078a178701a4a56305cfeffbdca556b2acb4202e Mon Sep 17 00:00:00 2001 From: Frank Dellaert Date: Thu, 4 Dec 2014 22:27:29 +0000 Subject: [PATCH] tag dispatching and template meta-programming --- GTSAM-Concepts.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/GTSAM-Concepts.md b/GTSAM-Concepts.md index 00fb3a86e..b3f366303 100644 --- a/GTSAM-Concepts.md +++ b/GTSAM-Concepts.md @@ -172,6 +172,44 @@ The group composition operation can be of two flavors: which should be queryable by `gtsam::traits::group_flavor::type` +A tag can be used for [tag dispatching](http://www.boost.org/community/generic_programming.html#tag_dispatching), +e.g., below is a generic compose: + +``` +#!c++ + namespace detail { + template + T compose(const T& p, const T& q, additive_group_tag) { + return p + q; + } + + template + T compose(const T& p, const T& q, multiplicative_group_tag) { + return p * q; + } + } + + template + T compose(const T& p, const T& q) { + return detail::compose(p, q, traits::group_flavor::type); + } +``` + +Tags also facilitate meta-programming. Taking a leaf from [The boost Graph library](http://www.boost.org/doc/libs/1_40_0/boost/graph/graph_traits.hpp), +tags can be used to create useful meta-functions, like `is_lie_group`, below. + +``` +#!c++ + template + struct is_lie_group + : mpl::bool_< + is_convertible< + typename structure_category::type, + lie_group_tag + >::value + > + { }; +``` Manifold Example ----------------