#ifndef LLVM_ADT_BREADTHFIRSTITERATOR_H
#define LLVM_ADT_BREADTHFIRSTITERATOR_H
#include "llvm/ADT/GraphTraits.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/iterator_range.h"
#include <iterator>
#include <optional>
#include <queue>
#include <utility>
namespace llvm {
template <class SetType> class bf_iterator_storage { … };
bf_iterator_default_set;
template <class GraphT,
class SetType =
bf_iterator_default_set<typename GraphTraits<GraphT>::NodeRef>,
class GT = GraphTraits<GraphT>>
class bf_iterator : public bf_iterator_storage<SetType> {
public:
using iterator_category = std::forward_iterator_tag;
using value_type = typename GT::NodeRef;
using difference_type = std::ptrdiff_t;
using pointer = value_type *;
using reference = const value_type &;
private:
using NodeRef = typename GT::NodeRef;
using ChildItTy = typename GT::ChildIteratorType;
using QueueElement = std::pair<NodeRef, std::optional<ChildItTy>>;
std::queue<std::optional<QueueElement>> VisitQueue;
unsigned Level = 0;
inline bf_iterator(NodeRef Node) { … }
inline bf_iterator() = default;
inline void toNext() { … }
public:
static bf_iterator begin(const GraphT &G) { … }
static bf_iterator end(const GraphT &G) { … }
bool operator==(const bf_iterator &RHS) const { … }
bool operator!=(const bf_iterator &RHS) const { … }
reference operator*() const { … }
NodeRef operator->() const { … }
bf_iterator &operator++() { … }
bf_iterator operator++(int) { … }
unsigned getLevel() const { … }
};
template <class T> bf_iterator<T> bf_begin(const T &G) { … }
template <class T> bf_iterator<T> bf_end(const T &G) { … }
template <class T> iterator_range<bf_iterator<T>> breadth_first(const T &G) { … }
}
#endif