1 /* Copyright (c) 2016-2023. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #ifndef SIMGRID_XBT_RANGE_HPP
7 #define SIMGRID_XBT_RANGE_HPP
11 namespace simgrid::xbt {
13 /** Describes a contiguous inclusive-exclusive [a,b) range of values */
14 template<class T> class Range {
18 Range() : begin_(), end_() {}
19 Range(T begin, T end) : begin_(std::move(begin)), end_(std::move(end)) {}
20 explicit Range(T value) : begin_(value), end_(value + 1) {}
21 T& begin() { return begin_; }
22 T& end() { return end_; }
23 const T& begin() const { return begin_; }
24 const T& end() const { return end_; }
25 bool empty() const { return begin_ >= end_; }
26 bool contain(T const& x) const { return begin_ <= x && end_ > x; }
29 } // namespace simgrid::xbt