Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / include / xbt / range.hpp
1 /* Copyright (c) 2016-2023. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #ifndef SIMGRID_XBT_RANGE_HPP
7 #define SIMGRID_XBT_RANGE_HPP
8
9 #include <algorithm>
10
11 namespace simgrid::xbt {
12
13 /** Describes a contiguous inclusive-exclusive [a,b) range of values */
14 template<class T> class Range {
15   T begin_;
16   T end_;
17 public:
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; }
27 };
28
29 } // namespace simgrid::xbt
30
31 #endif