Merge pull request #629 from borglab/feature/constexpr-symbolgenerator

SymbolGenerator: add chr() and made constexpr-capable
release/4.3a0
Varun Agrawal 2020-12-03 10:15:09 -05:00 committed by GitHub
commit 13db697bed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -167,10 +167,11 @@ inline Key Z(std::uint64_t j) { return Symbol('z', j); }
/** Generates symbol shorthands with alternative names different than the /** Generates symbol shorthands with alternative names different than the
* one-letter predefined ones. */ * one-letter predefined ones. */
class SymbolGenerator { class SymbolGenerator {
const char c_; const unsigned char c_;
public: public:
SymbolGenerator(const char c) : c_(c) {} constexpr SymbolGenerator(const unsigned char c) : c_(c) {}
Symbol operator()(const std::uint64_t j) const { return Symbol(c_, j); } Symbol operator()(const std::uint64_t j) const { return Symbol(c_, j); }
constexpr unsigned char chr() const { return c_; }
}; };
/// traits /// traits

View File

@ -59,6 +59,12 @@ TEST(Key, SymbolGenerator) {
EXPECT(assert_equal(a1, ddz1)); EXPECT(assert_equal(a1, ddz1));
} }
/* ************************************************************************* */
TEST(Key, SymbolGeneratorConstexpr) {
constexpr auto Z = gtsam::SymbolGenerator('x');
EXPECT(assert_equal(Z.chr(), 'x'));
}
/* ************************************************************************* */ /* ************************************************************************* */
template<int KeySize> template<int KeySize>
Key KeyTestValue(); Key KeyTestValue();