/** Iterator allowing for scanning through the children. */
typedef typename expr::NodeValue::iterator< NodeTemplate<ref_count> > iterator;
/** Constant iterator allowing for scanning through the children. */
- typedef typename expr::NodeValue::iterator< NodeTemplate<ref_count> > const_iterator;
+ using const_iterator =
+ typename expr::NodeValue::iterator<NodeTemplate<ref_count>>;
+ /**
+ * Reverse constant iterator allowing for scanning through the children in
+ * reverse order.
+ */
+ using const_reverse_iterator = std::reverse_iterator<
+ typename expr::NodeValue::iterator<NodeTemplate<ref_count>>>;
class kinded_iterator {
friend class NodeTemplate<ref_count>;
* Returns the const_iterator pointing to the first child.
* @return the const_iterator
*/
- inline const_iterator begin() const {
+ const_iterator begin() const
+ {
assertTNodeNotExpired();
return d_nv->begin< NodeTemplate<ref_count> >();
}
* beyond the last one.
* @return the end of the children const_iterator.
*/
- inline const_iterator end() const {
+ const_iterator end() const
+ {
assertTNodeNotExpired();
return d_nv->end< NodeTemplate<ref_count> >();
}
+ /**
+ * Returns the const_reverse_iterator pointing to the last child.
+ * @return the const_reverse_iterator
+ */
+ const_reverse_iterator rbegin() const
+ {
+ assertTNodeNotExpired();
+ return std::make_reverse_iterator(d_nv->end<NodeTemplate<ref_count>>());
+ }
+
+ /**
+ * Returns the const_reverse_iterator pointing to one before the first child.
+ * @return the end of the const_reverse_iterator.
+ */
+ const_reverse_iterator rend() const
+ {
+ assertTNodeNotExpired();
+ return std::make_reverse_iterator(d_nv->begin<NodeTemplate<ref_count>>());
+ }
+
/**
* Returns the iterator pointing to the first child, if the node's
* kind is the same as the parameter, otherwise returns the iterator
}
}
+TEST_F(TestNodeBlackNode, const_reverse_iterator)
+{
+ NodeBuilder b;
+ Node x = d_skolemManager->mkDummySkolem("x", d_nodeManager->booleanType());
+ Node y = d_skolemManager->mkDummySkolem("y", d_nodeManager->booleanType());
+ Node z = d_skolemManager->mkDummySkolem("z", d_nodeManager->booleanType());
+ Node n = b << x << y << z << kind::AND;
+
+ { // same for const iterator
+ const Node& c = n;
+ Node::const_reverse_iterator i = c.rbegin();
+ ASSERT_EQ(*i++, z);
+ ASSERT_EQ(*i++, y);
+ ASSERT_EQ(*i++, x);
+ ASSERT_EQ(i, n.rend());
+ }
+}
+
TEST_F(TestNodeBlackNode, kinded_iterator)
{
TypeNode integerType = d_nodeManager->integerType();