overload += operator in Ordering

release/4.3a0
Varun Agrawal 2023-06-29 12:12:48 -04:00
parent eb5604d037
commit 72734d184b
3 changed files with 33 additions and 13 deletions

View File

@ -281,6 +281,18 @@ void Ordering::print(const std::string& str,
cout.flush();
}
/* ************************************************************************* */
Ordering::This& Ordering::operator+=(Key key) {
this->push_back(key);
return *this;
}
/* ************************************************************************* */
Ordering::This& Ordering::operator,(Key key) {
this->push_back(key);
return *this;
}
/* ************************************************************************* */
Ordering::This& Ordering::operator+=(KeyVector& keys) {
this->insert(this->end(), keys.begin(), keys.end());

View File

@ -25,10 +25,6 @@
#include <gtsam/inference/MetisIndex.h>
#include <gtsam/base/FastSet.h>
#ifdef GTSAM_USE_BOOST_FEATURES
#include <boost/assign/list_inserter.hpp>
#endif
#include <algorithm>
#include <vector>
@ -61,15 +57,13 @@ public:
Base(keys.begin(), keys.end()) {
}
#ifdef GTSAM_USE_BOOST_FEATURES
/// Add new variables to the ordering as ordering += key1, key2, ... Equivalent to calling
/// push_back.
boost::assign::list_inserter<boost::assign_detail::call_push_back<This> > operator+=(
Key key) {
return boost::assign::make_list_inserter(
boost::assign_detail::call_push_back<This>(*this))(key);
}
#endif
/// Add new variables to the ordering as
/// `ordering += key1, key2, ...`.
This& operator+=(Key key);
/// Overloading the comma operator allows for chaining appends
// e.g. keys += key1, key2
This& operator,(Key key);
/**
* @brief Append new keys to the ordering as `ordering += keys`.

View File

@ -196,6 +196,20 @@ TEST(Ordering, csr_format_3) {
EXPECT(adjExpected == adjAcutal);
}
/* ************************************************************************* */
TEST(Ordering, AppendKey) {
using symbol_shorthand::X;
Ordering actual;
actual += X(0);
Ordering expected1{X(0)};
EXPECT(assert_equal(expected1, actual));
actual += X(1), X(2), X(3);
Ordering expected2{X(0), X(1), X(2), X(3)};
EXPECT(assert_equal(expected2, actual));
}
/* ************************************************************************* */
TEST(Ordering, AppendVector) {
using symbol_shorthand::X;