Commit 1c0a93cc authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz
Browse files

* src/graph/graph.hh (trans_iterator): Respect the forward_iterator API.

parent ac98d7c0
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <type_traits> #include <type_traits>
#include <tuple> #include <tuple>
#include <cassert> #include <cassert>
#include <iterator>
namespace spot namespace spot
{ {
...@@ -172,13 +173,29 @@ namespace spot ...@@ -172,13 +173,29 @@ namespace spot
// of that list. // of that list.
template <typename Graph> template <typename Graph>
class SPOT_API trans_iterator class SPOT_API trans_iterator:
std::iterator<std::forward_iterator_tag,
typename
std::conditional<std::is_const<Graph>::value,
const typename Graph::trans_storage_t,
typename Graph::trans_storage_t>::type>
{ {
typedef
std::iterator<std::forward_iterator_tag,
typename
std::conditional<std::is_const<Graph>::value,
const typename Graph::trans_storage_t,
typename Graph::trans_storage_t>::type>
super;
public: public:
typedef typename Graph::transition transition; typedef typename Graph::transition transition;
typedef typename Graph::trans_storage_t trans_storage_t;
trans_iterator(Graph* g, transition t): t_(t), g_(g) trans_iterator()
: g_(nullptr), t_(0)
{
}
trans_iterator(Graph* g, transition t): g_(g), t_(t)
{ {
} }
...@@ -192,9 +209,7 @@ namespace spot ...@@ -192,9 +209,7 @@ namespace spot
return t_ != o.t_; return t_ != o.t_;
} }
typename std::conditional<std::is_const<Graph>::value, typename super::reference
const trans_storage_t&,
trans_storage_t&>::type
operator*() operator*()
{ {
return g_->trans_storage(t_); return g_->trans_storage(t_);
...@@ -214,8 +229,8 @@ namespace spot ...@@ -214,8 +229,8 @@ namespace spot
} }
protected: protected:
transition t_;
Graph* g_; Graph* g_;
transition t_;
}; };
////////////////////////////////////////////////// //////////////////////////////////////////////////
...@@ -230,7 +245,7 @@ namespace spot ...@@ -230,7 +245,7 @@ namespace spot
public: public:
typedef typename Graph::transition transition; typedef typename Graph::transition transition;
state_out(Graph* g, transition t): state_out(Graph* g, transition t):
t_(t), g_(g) g_(g), t_(t)
{ {
} }
...@@ -241,7 +256,7 @@ namespace spot ...@@ -241,7 +256,7 @@ namespace spot
trans_iterator<Graph> end() trans_iterator<Graph> end()
{ {
return {nullptr, 0}; return {};
} }
void recycle(transition t) void recycle(transition t)
...@@ -250,8 +265,8 @@ namespace spot ...@@ -250,8 +265,8 @@ namespace spot
} }
protected: protected:
transition t_;
Graph* g_; Graph* g_;
transition t_;
}; };
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment