14#ifndef OR_TOOLS_ORTOOLS_SET_COVER_VIEWS_H
15#define OR_TOOLS_ORTOOLS_SET_COVER_VIEWS_H
17#include <absl/meta/type_traits.h>
18#include <absl/types/span.h>
44template <
typename RangeT>
46 absl::remove_cvref_t<decltype(std::declval<const RangeT>().begin())>;
47template <
typename RangeT>
49 decltype(*std::declval<range_const_iterator_type<RangeT>>())>;
52template <
typename IterT,
typename ValueT>
60 return !(*
static_cast<const IterT*
>(
this) != other);
65template <
typename ValueRangeT,
typename IndexT>
66decltype(
auto)
at(
const ValueRangeT* container, IndexT index) {
67 DCHECK(IndexT(0) <= index && index < IndexT(container->size()));
68 return (*container)[index];
82template <
typename IntT,
typename EnableVectorT>
88 : index_(index), is_active_(is_active) {
93 return index_ != other.index_;
103 void AdjustToValidValue() {
104 while (index_ < IntT(is_active_->size()) &&
111 const EnableVectorT* is_active_;
115 : is_active_(is_active) {}
124 const EnableVectorT* is_active_;
135template <
typename ValueT,
typename IndexT>
146 : values_(values), index_iter_(iter) {}
148 DCHECK_EQ(values_.data(), other.values_.data());
149 return index_iter_ != other.index_iter_;
155 decltype(
auto)
operator*()
const {
156 return values_[
static_cast<size_t>(*index_iter_)];
160 absl::Span<value_type> values_;
166 template <
typename ValueRangeT,
typename IndexRangeT>
168 : values_(
absl::MakeConstSpan(*values)),
169 indices_(
absl::MakeConstSpan(*indices)) {}
171 auto size()
const {
return indices_.size(); }
172 bool empty()
const {
return indices_.empty(); }
177 return values_[
static_cast<size_t>(index)];
185 absl::Span<value_type>
base()
const {
return values_; }
188 absl::Span<value_type> values_;
189 absl::Span<index_type> indices_;
204template <
typename ValueT,
typename EnableVectorT>
213 const EnableVectorT* is_active)
214 : iterator_(iterator), end_(
end), is_active_(is_active) {
215 AdjustToValidValue();
218 DCHECK_EQ(is_active_, other.is_active_);
219 return iterator_ != other.iterator_;
223 AdjustToValidValue();
226 decltype(
auto)
operator*()
const {
return *iterator_; }
229 void AdjustToValidValue() {
230 while (iterator_ != end_ && !
util::at(is_active_, *iterator_)) {
237 const EnableVectorT* is_active_;
240 template <
typename ValueRangeT>
242 : values_(
absl::MakeConstSpan(*values)), is_active_(is_active) {
243 DCHECK(values !=
nullptr);
244 DCHECK(is_active !=
nullptr);
246 ValueFilterViewIterator
begin()
const {
247 return ValueFilterViewIterator(values_.begin(), values_.end(), is_active_);
249 ValueFilterViewIterator
end()
const {
250 return ValueFilterViewIterator(values_.end(), values_.end(), is_active_);
254 template <
typename IndexT>
255 decltype(
auto)
operator[](IndexT index)
const {
256 decltype(
auto) value = values_[
static_cast<size_t>(index)];
258 <<
"Inactive value. Are you using relative indices?";
261 absl::Span<value_type>
base()
const {
return values_; }
264 absl::Span<value_type> values_;
265 const EnableVectorT* is_active_;
279template <
typename ValueT,
typename EnableVectorT>
291 : iterator_(iterator),
292 is_active_iter_(is_active_begin),
293 is_active_end_(is_active_end) {
294 AdjustToValidValue();
297 DCHECK(is_active_end_ == other.is_active_end_);
298 return iterator_ != other.iterator_;
303 AdjustToValidValue();
306 decltype(
auto)
operator*()
const {
return *iterator_; }
309 void AdjustToValidValue() {
310 while (is_active_iter_ != is_active_end_ && !*is_active_iter_) {
321 template <
typename ValueRangeT>
323 : values_(
absl::MakeConstSpan(*values)), is_active_(is_active_) {
324 DCHECK(values !=
nullptr);
325 DCHECK(is_active_ !=
nullptr);
326 DCHECK_EQ(values->size(), is_active_->size());
336 absl::Span<value_type>
base()
const {
return values_; }
339 template <
typename IndexT>
340 decltype(
auto)
operator[](IndexT index)
const {
342 <<
"Inactive value. Are you using relative indices?";
343 return values_[
static_cast<size_t>(index)];
347 absl::Span<value_type> values_;
348 const EnableVectorT* is_active_;
358template <
typename Lvl1ViewT,
typename EnableVectorT>
369 const EnableVectorT* active_items)
370 : iter_(iter), active_items_(active_items) {}
372 DCHECK_EQ(active_items_, other.active_items_);
373 return iter_ != other.iter_;
382 const Lvl1ViewT&
base()
const {
return *
this; }
386 const EnableVectorT* active_items_;
391 : Lvl1ViewT(lvl1_view), active_items_(active_items) {}
399 template <
typename indexT>
401 auto& level2_container = Lvl1ViewT::operator[](i);
402 return level2_type(&level2_container, active_items_);
406 const EnableVectorT* active_items_;
410 template <
typename T>
412 return std::forward<T>(value);
416template <
typename FromT,
typename ToT>
418 ToT
operator()(FromT value)
const {
return static_cast<ToT
>(value); }
428template <
typename ValueT,
typename IndexT,
429 typename ValueTransformT = NoTransform>
439 return iterator_ != other.iterator_;
445 decltype(
auto)
operator*()
const {
return ValueTransformT()(*iterator_); }
453 template <
typename ValueRangeT>
455 : values_(
absl::MakeConstSpan(*values)) {}
457 auto size()
const {
return values_.size(); }
458 bool empty()
const {
return values_.empty(); }
460 decltype(
auto)
operator[](IndexT index)
const {
461 return ValueTransformT()(values_[
static_cast<size_t>(index)]);
469 absl::Span<value_type>
base()
const {
return values_; }
472 absl::Span<value_type> values_;
FilterIndexRangeView(const EnableVectorT *is_active)
FilterIndicesViewIterator end() const
FilterIndicesViewIterator begin() const
IndexFilterViewIterator end() const
IndexFilterViewIterator begin() const
IndexFilterView(const ValueRangeT *values, const EnableVectorT *is_active_)
absl::Span< value_type > base() const
typename absl::Span< value_type >::iterator value_iterator
util::range_const_iterator_type< EnableVectorT > enable_iterator
IndexListViewIterator end() const
typename absl::Span< index_type >::iterator index_iterator
typename absl::Span< value_type >::iterator value_iterator
IndexListViewIterator begin() const
absl::Span< value_type > base() const
IndexListView(const ValueRangeT *values, const IndexRangeT *indices)
ValueFilterView< level2_value, EnableVectorT > level2_type
util::range_const_iterator_type< Lvl1ViewT > level1_iterator
util::range_value_type< level1_value > level2_value
TwoLevelsViewIterator end() const
TwoLevelsViewIterator begin() const
level2_type operator[](indexT i) const
util::range_value_type< Lvl1ViewT > level1_value
TwoLevelsView(Lvl1ViewT lvl1_view, const EnableVectorT *active_items)
ValueFilterViewIterator begin() const
absl::Span< value_type > base() const
ValueFilterViewIterator end() const
typename absl::Span< value_type >::iterator value_iterator
ValueFilterView(const ValueRangeT *values, const EnableVectorT *is_active)
absl::remove_cvref_t< decltype(std::declval< const RangeT >().begin())> range_const_iterator_type
decltype(auto) at(const ValueRangeT *container, IndexT index)
absl::remove_cvref_t< decltype(*std::declval< range_const_iterator_type< RangeT > >())> range_value_type
A collections of i/o utilities for the Graph classes in ./graph.h.
FilterIndicesViewIterator & operator++()
bool operator!=(FilterIndicesViewIterator other) const
FilterIndicesViewIterator(IntT index, const EnableVectorT *is_active)
IndexFilterViewIterator & operator++()
bool operator!=(const IndexFilterViewIterator &other) const
IndexFilterViewIterator(value_iterator iterator, enable_iterator is_active_begin, enable_iterator is_active_end)
bool operator!=(const IndexListViewIterator &other) const
IndexListViewIterator(absl::Span< value_type > values, index_iterator iter)
IndexListViewIterator & operator++()
bool operator!=(const TwoLevelsViewIterator &other) const
TwoLevelsViewIterator & operator++()
level2_type operator*() const
TwoLevelsViewIterator(level1_iterator iter, const EnableVectorT *active_items)
const Lvl1ViewT & base() const
bool operator!=(const ValueFilterViewIterator &other) const
ValueFilterViewIterator & operator++()
ValueFilterViewIterator(value_iterator iterator, value_iterator end, const EnableVectorT *is_active)
Enable compatibility with STL algorithms.
std::input_iterator_tag iterator_category
pointer operator->() const
std::ptrdiff_t difference_type
bool operator==(const IterT &other) const