replaced lambda with class plus functor

release/4.3a0
Jose Luis Blanco Claraco 2020-10-24 08:41:00 +02:00
parent 7aab3796b0
commit e3a28767ed
No known key found for this signature in database
GPG Key ID: D443304FBD70A641
2 changed files with 10 additions and 9 deletions

View File

@ -165,13 +165,15 @@ inline Key Z(std::uint64_t j) { return Symbol('z', j); }
/** Generates symbol shorthands with alternative names different than the
* one-letter predefined ones. */
inline std::function<Key(std::uint64_t)> alternativeName(const char c) {
return [c](std::uint64_t j) { return gtsam::Symbol(c, j); };
}
class SymbolGenerator {
const char c_;
public:
SymbolGenerator(const char c) : c_(c) {}
Symbol operator()(const std::uint64_t j) const { return Symbol(c_, j); }
};
}
/// traits
template<> struct traits<Symbol> : public Testable<Symbol> {};
} // \ namespace gtsam

View File

@ -41,14 +41,14 @@ TEST(Key, KeySymbolConversion) {
}
/* ************************************************************************* */
TEST(Key, SymbolAlternativeNames) {
TEST(Key, SymbolGenerator) {
const auto x1 = gtsam::symbol_shorthand::X(1);
const auto v1 = gtsam::symbol_shorthand::V(1);
const auto a1 = gtsam::symbol_shorthand::A(1);
const auto Z = gtsam::symbol_shorthand::alternativeName('x');
const auto DZ = gtsam::symbol_shorthand::alternativeName('v');
const auto DDZ = gtsam::symbol_shorthand::alternativeName('a');
const auto Z = gtsam::symbol_shorthand::SymbolGenerator('x');
const auto DZ = gtsam::symbol_shorthand::SymbolGenerator('v');
const auto DDZ = gtsam::symbol_shorthand::SymbolGenerator('a');
const auto z1 = Z(1);
const auto dz1 = DZ(1);
@ -125,4 +125,3 @@ int main() {
return TestRegistry::runAllTests(tr);
}
/* ************************************************************************* */