diff options
author | Ouyancheng <1024842937@qq.com> | 2021-10-12 02:44:50 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-12 09:44:50 +0000 |
commit | 069fde2aac69f741bc7679f64bbdc9aed4874b73 (patch) | |
tree | 51bfe4c10d06ecdb02b740329ae443539967cdf7 /src/api | |
parent | 2a711652b9715ec931bab431dc0f4b66f1bf70da (diff) |
fix deprecation of std::iterator (#7332)
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
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/cpp/cvc5.h | 62 |
1 files changed, 59 insertions, 3 deletions
diff --git a/src/api/cpp/cvc5.h b/src/api/cpp/cvc5.h index 73b3d1ee9..3db581db6 100644 --- a/src/api/cpp/cvc5.h +++ b/src/api/cpp/cvc5.h @@ -1167,11 +1167,30 @@ class CVC5_EXPORT Term * 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. */ @@ -1951,11 +1970,29 @@ class CVC5_EXPORT DatatypeConstructor * 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(); @@ -2184,11 +2221,30 @@ class CVC5_EXPORT Datatype /** * 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(); |