diff --git a/gtsam/inference/Symbol.h b/gtsam/inference/Symbol.h index 469082f16..42cdbb1c3 100644 --- a/gtsam/inference/Symbol.h +++ b/gtsam/inference/Symbol.h @@ -167,10 +167,11 @@ inline Key Z(std::uint64_t j) { return Symbol('z', j); } /** Generates symbol shorthands with alternative names different than the * one-letter predefined ones. */ class SymbolGenerator { - const char c_; + const unsigned char c_; 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); } + constexpr unsigned char chr() const { return c_; } }; /// traits diff --git a/gtsam/inference/tests/testKey.cpp b/gtsam/inference/tests/testKey.cpp index 64674c36f..98c5d36bf 100644 --- a/gtsam/inference/tests/testKey.cpp +++ b/gtsam/inference/tests/testKey.cpp @@ -59,6 +59,12 @@ TEST(Key, SymbolGenerator) { EXPECT(assert_equal(a1, ddz1)); } +/* ************************************************************************* */ +TEST(Key, SymbolGeneratorConstexpr) { + constexpr auto Z = gtsam::SymbolGenerator('x'); + EXPECT(assert_equal(Z.chr(), 'x')); +} + /* ************************************************************************* */ template Key KeyTestValue();