Add MapById<>::ConstIterator::operator->(). (#580)
parent
cb41777b9e
commit
4ab4817104
|
@ -21,10 +21,12 @@
|
|||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
#include "cartographer/common/make_unique.h"
|
||||
#include "cartographer/common/port.h"
|
||||
#include "glog/logging.h"
|
||||
|
||||
|
@ -129,7 +131,7 @@ class MapById {
|
|||
using iterator_category = std::bidirectional_iterator_tag;
|
||||
using value_type = IdDataReference;
|
||||
using difference_type = int64;
|
||||
using pointer = const IdDataReference*;
|
||||
using pointer = std::unique_ptr<const IdDataReference>;
|
||||
using reference = const IdDataReference&;
|
||||
|
||||
explicit ConstIterator(const MapById& map_by_id, const int trajectory_id)
|
||||
|
@ -149,6 +151,10 @@ class MapById {
|
|||
current_data_->second};
|
||||
}
|
||||
|
||||
std::unique_ptr<const IdDataReference> operator->() const {
|
||||
return common::make_unique<const IdDataReference>(this->operator*());
|
||||
}
|
||||
|
||||
ConstIterator& operator++() {
|
||||
CHECK(current_trajectory_ != end_trajectory_);
|
||||
++current_data_;
|
||||
|
|
|
@ -41,7 +41,7 @@ TEST(IdTest, MapByIdIterator) {
|
|||
map_by_id.Append(42, 3);
|
||||
map_by_id.Append(0, 0);
|
||||
map_by_id.Append(0, 1);
|
||||
EXPECT_EQ(2, (*map_by_id.BeginOfTrajectory(7)).data);
|
||||
EXPECT_EQ(2, map_by_id.BeginOfTrajectory(7)->data);
|
||||
EXPECT_TRUE(std::next(map_by_id.BeginOfTrajectory(7)) ==
|
||||
map_by_id.EndOfTrajectory(7));
|
||||
std::deque<std::pair<NodeId, int>> expected_id_data = {
|
||||
|
|
|
@ -72,7 +72,7 @@ std::vector<mapping::SubmapId> SparsePoseGraph::GrowSubmapTransformsAsNeeded(
|
|||
CHECK_EQ(2, insertion_submaps.size());
|
||||
const auto end_it = submap_data.EndOfTrajectory(trajectory_id);
|
||||
CHECK(submap_data.BeginOfTrajectory(trajectory_id) != end_it);
|
||||
const mapping::SubmapId last_submap_id = (*std::prev(end_it)).id;
|
||||
const mapping::SubmapId last_submap_id = std::prev(end_it)->id;
|
||||
if (submap_data_.at(last_submap_id).submap == insertion_submaps.front()) {
|
||||
// In this case, 'last_submap_id' is the ID of 'insertions_submaps.front()'
|
||||
// and 'insertions_submaps.back()' is new.
|
||||
|
@ -596,7 +596,7 @@ transform::Rigid3d SparsePoseGraph::ComputeLocalToGlobalTransform(
|
|||
if (begin_it == end_it) {
|
||||
return transform::Rigid3d::Identity();
|
||||
}
|
||||
const mapping::SubmapId last_optimized_submap_id = (*std::prev(end_it)).id;
|
||||
const mapping::SubmapId last_optimized_submap_id = std::prev(end_it)->id;
|
||||
// Accessing 'local_pose' in Submap is okay, since the member is const.
|
||||
return transform::Embed3D(
|
||||
submap_transforms.at(last_optimized_submap_id).pose) *
|
||||
|
|
Loading…
Reference in New Issue