Values initializer_list constructor
parent
c9fb096002
commit
77c8c3bf0b
|
@ -52,6 +52,12 @@ namespace gtsam {
|
||||||
Values::Values(Values&& other) : values_(std::move(other.values_)) {
|
Values::Values(Values&& other) : values_(std::move(other.values_)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
Values::Values(std::initializer_list<ConstKeyValuePair> init) {
|
||||||
|
for (const auto &kv : init)
|
||||||
|
insert(kv.key, kv.value);
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
Values::Values(const Values& other, const VectorValues& delta) {
|
Values::Values(const Values& other, const VectorValues& delta) {
|
||||||
for (const_iterator key_value = other.begin(); key_value != other.end(); ++key_value) {
|
for (const_iterator key_value = other.begin(); key_value != other.end(); ++key_value) {
|
||||||
|
|
|
@ -149,6 +149,13 @@ namespace gtsam {
|
||||||
|
|
||||||
/** Move constructor */
|
/** Move constructor */
|
||||||
Values(Values&& other);
|
Values(Values&& other);
|
||||||
|
|
||||||
|
/** Constructor from initializer list. Example usage:
|
||||||
|
* \code
|
||||||
|
* Values v = {{k1, genericValue(pose1)}, {k2, genericValue(point2)}};
|
||||||
|
* \endcode
|
||||||
|
*/
|
||||||
|
Values(std::initializer_list<ConstKeyValuePair> init);
|
||||||
|
|
||||||
/** Construct from a Values and an update vector: identical to other.retract(delta) */
|
/** Construct from a Values and an update vector: identical to other.retract(delta) */
|
||||||
Values(const Values& other, const VectorValues& delta);
|
Values(const Values& other, const VectorValues& delta);
|
||||||
|
|
|
@ -606,6 +606,36 @@ TEST(Values, Demangle) {
|
||||||
EXPECT(assert_equal(expected, actual));
|
EXPECT(assert_equal(expected, actual));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
TEST(Values, brace_initializer) {
|
||||||
|
const Pose2 poseA(1.0, 2.0, 0.3), poseC(.0, .0, .0);
|
||||||
|
const Pose3 poseB(Pose2(0.1, 0.2, 0.3));
|
||||||
|
|
||||||
|
{
|
||||||
|
Values values;
|
||||||
|
EXPECT_LONGS_EQUAL(0, values.size());
|
||||||
|
values = { {key1, genericValue(1.0)} };
|
||||||
|
EXPECT_LONGS_EQUAL(1, values.size());
|
||||||
|
CHECK(values.at<double>(key1) == 1.0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
Values values = { {key1, genericValue(poseA)}, {key2, genericValue(poseB)} };
|
||||||
|
EXPECT_LONGS_EQUAL(2, values.size());
|
||||||
|
EXPECT(assert_equal(values.at<Pose2>(key1), poseA));
|
||||||
|
EXPECT(assert_equal(values.at<Pose3>(key2), poseB));
|
||||||
|
}
|
||||||
|
// Test exception: duplicated key:
|
||||||
|
{
|
||||||
|
Values values;
|
||||||
|
CHECK_EXCEPTION((values = {
|
||||||
|
{key1, genericValue(poseA)},
|
||||||
|
{key2, genericValue(poseB)},
|
||||||
|
{key1, genericValue(poseC)}
|
||||||
|
}), std::exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
int main() { TestResult tr; return TestRegistry::runAllTests(tr); }
|
int main() { TestResult tr; return TestRegistry::runAllTests(tr); }
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
Loading…
Reference in New Issue