Added some more functions and fixed both flag paths.
parent
b281f62e24
commit
f2fff1936b
|
@ -163,14 +163,14 @@ namespace gtsam {
|
|||
&ValuesCastHelper<ValueType, KeyValuePair, Values::KeyValuePair>::cast)), constBegin_(
|
||||
boost::make_transform_iterator(
|
||||
boost::make_filter_iterator(filter,
|
||||
((const Values&) values).begin(),
|
||||
((const Values&) values).end()),
|
||||
values._begin(),
|
||||
values._end()),
|
||||
&ValuesCastHelper<ValueType, ConstKeyValuePair,
|
||||
Values::ConstKeyValuePair>::cast)), constEnd_(
|
||||
boost::make_transform_iterator(
|
||||
boost::make_filter_iterator(filter,
|
||||
((const Values&) values).end(),
|
||||
((const Values&) values).end()),
|
||||
values._end(),
|
||||
values._end()),
|
||||
&ValuesCastHelper<ValueType, ConstKeyValuePair,
|
||||
Values::ConstKeyValuePair>::cast)) {
|
||||
}
|
||||
|
|
|
@ -187,23 +187,36 @@ namespace gtsam {
|
|||
/// @name Iterator
|
||||
/// @{
|
||||
|
||||
struct const_iterator {
|
||||
struct deref_iterator {
|
||||
using const_iterator_type = typename KeyValueMap::const_iterator;
|
||||
const_iterator_type it_;
|
||||
const_iterator(const_iterator_type it) : it_(it) {}
|
||||
std::pair<size_t, const Value&> operator*() const {
|
||||
return {it_->first, *(it_->second)};
|
||||
deref_iterator(const_iterator_type it) : it_(it) {}
|
||||
ConstKeyValuePair operator*() const { return {it_->first, *(it_->second)}; }
|
||||
std::unique_ptr<ConstKeyValuePair> operator->() {
|
||||
return std::make_unique<ConstKeyValuePair>(it_->first, *(it_->second));
|
||||
}
|
||||
bool operator==(const const_iterator& other) const { return it_ == other.it_; }
|
||||
bool operator!=(const const_iterator& other) const { return it_ != other.it_; }
|
||||
const_iterator& operator++() {
|
||||
bool operator==(const deref_iterator& other) const {
|
||||
return it_ == other.it_;
|
||||
}
|
||||
bool operator!=(const deref_iterator& other) const { return it_ != other.it_; }
|
||||
deref_iterator& operator++() {
|
||||
++it_;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
const_iterator begin() { return const_iterator(values_.begin()); }
|
||||
const_iterator end() { return const_iterator(values_.end()); }
|
||||
deref_iterator begin() const { return deref_iterator(values_.begin()); }
|
||||
deref_iterator end() const { return deref_iterator(values_.end()); }
|
||||
|
||||
/** Find an element by key, returning an iterator, or end() if the key was
|
||||
* not found. */
|
||||
deref_iterator find(Key j) const { return deref_iterator(values_.find(j)); }
|
||||
|
||||
/** Find the element greater than or equal to the specified key. */
|
||||
deref_iterator lower_bound(Key j) const { return deref_iterator(values_.lower_bound(j)); }
|
||||
|
||||
/** Find the lowest-ordered element greater than the specified key. */
|
||||
deref_iterator upper_bound(Key j) const { return deref_iterator(values_.upper_bound(j)); }
|
||||
|
||||
/// @}
|
||||
/// @name Manifold Operations
|
||||
|
@ -363,8 +376,8 @@ namespace gtsam {
|
|||
static KeyValuePair make_deref_pair(const KeyValueMap::iterator::value_type& key_value) {
|
||||
return KeyValuePair(key_value.first, *key_value.second); }
|
||||
|
||||
const_iterator begin() const { return boost::make_transform_iterator(values_.begin(), &make_const_deref_pair); }
|
||||
const_iterator end() const { return boost::make_transform_iterator(values_.end(), &make_const_deref_pair); }
|
||||
const_iterator _begin() const { return boost::make_transform_iterator(values_.begin(), &make_const_deref_pair); }
|
||||
const_iterator _end() const { return boost::make_transform_iterator(values_.end(), &make_const_deref_pair); }
|
||||
iterator begin() { return boost::make_transform_iterator(values_.begin(), &make_deref_pair); }
|
||||
iterator end() { return boost::make_transform_iterator(values_.end(), &make_deref_pair); }
|
||||
const_reverse_iterator rbegin() const { return boost::make_transform_iterator(values_.rbegin(), &make_const_deref_pair); }
|
||||
|
@ -376,22 +389,12 @@ namespace gtsam {
|
|||
* not found. */
|
||||
iterator find(Key j) { return boost::make_transform_iterator(values_.find(j), &make_deref_pair); }
|
||||
|
||||
/** Find an element by key, returning an iterator, or end() if the key was
|
||||
* not found. */
|
||||
const_iterator find(Key j) const { return boost::make_transform_iterator(values_.find(j), &make_const_deref_pair); }
|
||||
|
||||
/** Find the element greater than or equal to the specified key. */
|
||||
iterator lower_bound(Key j) { return boost::make_transform_iterator(values_.lower_bound(j), &make_deref_pair); }
|
||||
|
||||
/** Find the element greater than or equal to the specified key. */
|
||||
const_iterator lower_bound(Key j) const { return boost::make_transform_iterator(values_.lower_bound(j), &make_const_deref_pair); }
|
||||
|
||||
/** Find the lowest-ordered element greater than the specified key. */
|
||||
iterator upper_bound(Key j) { return boost::make_transform_iterator(values_.upper_bound(j), &make_deref_pair); }
|
||||
|
||||
/** Find the lowest-ordered element greater than the specified key. */
|
||||
const_iterator upper_bound(Key j) const { return boost::make_transform_iterator(values_.upper_bound(j), &make_const_deref_pair); }
|
||||
|
||||
/** A filtered view of a Values, returned from Values::filter. */
|
||||
template <class ValueType = Value>
|
||||
class Filtered;
|
||||
|
|
|
@ -203,7 +203,6 @@ TEST(Values, basic_functions)
|
|||
}
|
||||
EXPECT_LONGS_EQUAL(4, count);
|
||||
|
||||
#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V42
|
||||
// find
|
||||
EXPECT_LONGS_EQUAL(4, values.find(4)->key);
|
||||
EXPECT_LONGS_EQUAL(4, values_c.find(4)->key);
|
||||
|
@ -219,7 +218,6 @@ TEST(Values, basic_functions)
|
|||
EXPECT_LONGS_EQUAL(6, values_c.upper_bound(4)->key);
|
||||
EXPECT_LONGS_EQUAL(4, values.upper_bound(3)->key);
|
||||
EXPECT_LONGS_EQUAL(4, values_c.upper_bound(3)->key);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
|
|
Loading…
Reference in New Issue