diff --git a/gtsam/base/concepts.h b/gtsam/base/concepts.h index 39e707a95..3eabdd3ad 100644 --- a/gtsam/base/concepts.h +++ b/gtsam/base/concepts.h @@ -149,6 +149,17 @@ check_invariants(const T& a, const T& b, double tol = 1e-9) { } } // \ namespace group +#define GTSAM_ADDITIVE_GROUP1(T1,A1,GROUP) \ +namespace group { \ +template GROUP compose(const GROUP &g, const GROUP & h) { return g + h;} \ +template GROUP between(const GROUP &g, const GROUP & h) { return h - g;} \ +template GROUP inverse(const GROUP &g) { return -g;} \ +namespace traits { \ +template struct identity > { static const GROUP value; typedef GROUP value_type;};\ +template const GROUP identity >::value = GROUP::Identity();\ +template struct flavor > { typedef additive_tag type;};\ +}} + #define GTSAM_MULTIPLICATIVE_GROUP2(T1,A1,T2,A2,GROUP) \ namespace group { \ template GROUP compose(const GROUP &g, const GROUP & h) { return g * h;} \ diff --git a/gtsam/geometry/Cyclic.h b/gtsam/geometry/Cyclic.h index 94d302d5b..f97f05dc8 100644 --- a/gtsam/geometry/Cyclic.h +++ b/gtsam/geometry/Cyclic.h @@ -20,34 +20,15 @@ namespace gtsam { -/// Additive Group, using CRTP -template -struct AdditiveGroup { - static Derived Identity() { - return Derived::Identity(); - } - Derived const * derived() const { - return static_cast(this); - } - Derived operator+(const AdditiveGroup& h) const { - return derived()->operator+(*h.derived()); - } - Derived operator-(const AdditiveGroup& h) const { - return derived()->operator-(*h.derived()); - } - Derived operator-() const { - return derived()->operator-(); - } -}; - /// Cyclic group of order N template -class Cyclic : public AdditiveGroup > { +class Cyclic { size_t i_; ///< we just use an unsigned int public: /// Constructor Cyclic(size_t i) : i_(i) { + assert(i -struct structure_category > { +/// Define cyclic group to be a model of the Group concept +template +struct structure_category > { typedef group_tag type; }; } // \namespace gtsam::traits -namespace group { - -template -G compose(const AdditiveGroup&g, const AdditiveGroup& h) { - return g + h; -} - -template -G between(const AdditiveGroup&g, const AdditiveGroup& h) { - return h - g; -} - -template -G inverse(const AdditiveGroup&g) { - return -g; -} - -namespace traits { - -/// Define the trait that specifies Cyclic's identity element -template struct identity > { - static const G value; - typedef G value_type; -}; - -template -const G identity >::value = AdditiveGroup::Identity(); - -/// Define the trait that asserts AdditiveGroup is an additive group -template struct flavor > { - typedef additive_tag type; -}; - -} // \namespace gtsam::group::traits -} // \namespace gtsam::group } // \namespace gtsam diff --git a/gtsam/geometry/tests/testCyclic.cpp b/gtsam/geometry/tests/testCyclic.cpp index 95ed1b5b9..dfc94f36e 100644 --- a/gtsam/geometry/tests/testCyclic.cpp +++ b/gtsam/geometry/tests/testCyclic.cpp @@ -26,7 +26,7 @@ typedef Cyclic<6> G; // Let's use the cyclic group of order 6 //****************************************************************************** TEST(Cyclic, Concept) { -// BOOST_CONCEPT_ASSERT((IsGroup)); + BOOST_CONCEPT_ASSERT((IsGroup)); // BOOST_CONCEPT_ASSERT((IsGroup >)); EXPECT_LONGS_EQUAL(0, group::traits::identity::value); G g(2), h(3);