When compiling cvc5 with clang-13, it will emit lots of warnings of usages of `std::iterator` as it's deprecated since C++17.
The recommended implementation of iterators is to manually define the following five types:
```
template< class Iter >
struct iterator_traits;
difference_type Iter::difference_type
value_type Iter::value_type
pointer Iter::pointer
reference Iter::reference
iterator_category Iter::iterator_category
```
And the iterator-related types could be accessed by for example `typename std::iterator_traits<Iter>::value_type value`.
This pull request performs the fix, and the program is semantically equivalent before and after the fix.
References:
https://en.cppreference.com/w/cpp/iterator/iterator_traits
https://en.cppreference.com/w/cpp/iterator/iterator
* for example, the term f(x, y) will have Kind APPLY_UF and three
* children: f, x, and y
*/
- class const_iterator : public std::iterator<std::input_iterator_tag, Term>
+ class const_iterator
{
friend class Term;
public:
+ /* The following types are required by trait std::iterator_traits */
+
+ /** Iterator tag */
+ using iterator_category = std::forward_iterator_tag;
+
+ /** The type of the item */
+ using value_type = Term;
+
+ /** The pointer type of the item */
+ using pointer = const Term*;
+
+ /** The reference type of the item */
+ using reference = const Term&;
+
+ /** The type returned when two iterators are subtracted */
+ using difference_type = std::ptrdiff_t;
+
+ /* End of std::iterator_traits required types */
+
/**
* Null Constructor.
*/
* Iterator for the selectors of a datatype constructor.
*/
class const_iterator
- : public std::iterator<std::input_iterator_tag, DatatypeConstructor>
{
friend class DatatypeConstructor; // to access constructor
public:
+ /* The following types are required by trait std::iterator_traits */
+
+ /** Iterator tag */
+ using iterator_category = std::forward_iterator_tag;
+
+ /** The type of the item */
+ using value_type = DatatypeConstructor;
+
+ /** The pointer type of the item */
+ using pointer = const DatatypeConstructor*;
+
+ /** The reference type of the item */
+ using reference = const DatatypeConstructor&;
+
+ /** The type returned when two iterators are subtracted */
+ using difference_type = std::ptrdiff_t;
+
+ /* End of std::iterator_traits required types */
+
/** Nullary constructor (required for Cython). */
const_iterator();
/**
* Iterator for the constructors of a datatype.
*/
- class const_iterator : public std::iterator<std::input_iterator_tag, Datatype>
+ class const_iterator
{
friend class Datatype; // to access constructor
public:
+ /* The following types are required by trait std::iterator_traits */
+
+ /** Iterator tag */
+ using iterator_category = std::forward_iterator_tag;
+
+ /** The type of the item */
+ using value_type = Datatype;
+
+ /** The pointer type of the item */
+ using pointer = const Datatype*;
+
+ /** The reference type of the item */
+ using reference = const Datatype&;
+
+ /** The type returned when two iterators are subtracted */
+ using difference_type = std::ptrdiff_t;
+
+ /* End of std::iterator_traits required types */
+
/** Nullary constructor (required for Cython). */
const_iterator();
const Element* d_it;
public:
- using iterator_category = std::input_iterator_tag;
+ using iterator_category = std::forward_iterator_tag;
using value_type = typename CDOhash_map<Key, Data, HashFcn>::value_type;
using difference_type = ptrdiff_t;
using pointer = typename CDOhash_map<Key, Data, HashFcn>::value_type*;
// FIXME we support operator--, but do we satisfy all the
// requirements of a bidirectional iterator ?
- typedef std::input_iterator_tag iterator_category;
+ typedef std::bidirectional_iterator_tag iterator_category;
typedef T value_type;
typedef std::ptrdiff_t difference_type;
typedef const T* pointer;
namespace cvc5 {
namespace expr {
-class NodeSelfIterator : public std::iterator<std::input_iterator_tag, Node> {
+class NodeSelfIterator {
Node d_node;
Node::const_iterator d_child;
public:
+ /* The following types are required by trait std::iterator_traits */
+
+ /** Iterator tag */
+ using iterator_category = std::forward_iterator_tag;
+
+ /** The type of the item */
+ using value_type = Node;
+
+ /** The pointer type of the item */
+ using pointer = Node*;
+
+ /** The reference type of the item */
+ using reference = Node&;
+
+ /** The type returned when two iterators are subtracted */
+ using difference_type = std::ptrdiff_t;
+
+ /* End of std::iterator_traits required types */
+
static NodeSelfIterator self(TNode n);
static NodeSelfIterator selfEnd(TNode n);
public:
- class iterator : public std::iterator<std::input_iterator_tag, Variable> {
+ class iterator {
private:
internal_iterator d_iter;
public:
+ /* The following types are required by trait std::iterator_traits */
+
+ /** Iterator tag */
+ using iterator_category = std::forward_iterator_tag;
+
+ /** The type of the item */
+ using value_type = Variable;
+
+ /** The pointer type of the item */
+ using pointer = Variable*;
+
+ /** The reference type of the item */
+ using reference = Variable&;
+
+ /** The type returned when two iterators are subtracted */
+ using difference_type = std::ptrdiff_t;
+
+ /* End of std::iterator_traits required types */
+
explicit iterator(internal_iterator i) : d_iter(i) {}
inline Variable operator*() {
public:
static bool isMember(TNode n);
- class iterator : public std::iterator<std::input_iterator_tag, Monomial> {
+ class iterator {
private:
internal_iterator d_iter;
public:
+ /* The following types are required by trait std::iterator_traits */
+
+ /** Iterator tag */
+ using iterator_category = std::forward_iterator_tag;
+
+ /** The type of the item */
+ using value_type = Monomial;
+
+ /** The pointer type of the item */
+ using pointer = Monomial*;
+
+ /** The reference type of the item */
+ using reference = Monomial&;
+
+ /** The type returned when two iterators are subtracted */
+ using difference_type = std::ptrdiff_t;
+
+ /* End of std::iterator_traits required types */
+
explicit iterator(internal_iterator i) : d_iter(i) {}
inline Monomial operator*() {
}; /* BinaryHeap<>::handle */
- class const_iterator : public std::iterator<std::input_iterator_tag, Elem> {
+ class const_iterator {
+ public:
+ /* The following types are required by trait std::iterator_traits */
+
+ /** Iterator tag */
+ using iterator_category = std::forward_iterator_tag;
+
+ /** The type of the item */
+ using value_type = Elem;
+
+ /** The pointer type of the item */
+ using pointer = const Elem*;
+
+ /** The reference type of the item */
+ using reference = const Elem&;
+
+ /** The type returned when two iterators are subtracted */
+ using difference_type = std::ptrdiff_t;
+
+ /* End of std::iterator_traits required types */
+
private:
typename ElementVector::const_iterator d_iter;
friend class BinaryHeap;