Interval API Reference¶
Complete API documentation for the interval<T>
class template.
Class Template¶
Template Parameters¶
- T: The value type for interval boundaries. Must satisfy the
Boundary
concept (totally ordered and regular).
Common Type Aliases¶
Named Constructors (Factory Methods)¶
Bounded Intervals¶
closed(T lower, T upper)
¶
Creates a closed interval \([a, b]\) that includes both endpoints. Example:
auto i = real_interval::closed(0, 10); // [0, 10]
assert(i.contains(0)); // true
assert(i.contains(10)); // true
open(T lower, T upper)
¶
Creates an open interval \((a, b)\) that excludes both endpoints. Example:
auto i = real_interval::open(0, 10); // (0, 10)
assert(!i.contains(0)); // false
assert(!i.contains(10)); // false
assert(i.contains(5)); // true
left_open(T lower, T upper)
¶
Creates a left-open interval \((a, b]\). right_open(T lower, T upper)
¶
Creates a right-open interval \([a, b)\). Special Intervals¶
point(T value)
¶
Creates a singleton interval \(\{x\}\) containing exactly one point. empty()
¶
Creates an empty interval \(\emptyset\). Unbounded Intervals¶
Requires std::numeric_limits<T>::has_infinity
.
unbounded()
¶
Creates \((-\infty, \infty)\). at_least(T lower)
¶
Creates \([a, \infty)\). greater_than(T lower)
¶
Creates \((a, \infty)\). at_most(T upper)
¶
Creates \((-\infty, b]\). less_than(T upper)
¶
Creates \((-\infty, b)\). Member Functions¶
Queries¶
is_empty()
¶
Returns true
if interval contains no points. contains(T value)
¶
Tests if value is in interval. overlaps(const interval& other)
¶
Tests if intervals have non-empty intersection. Accessors¶
lower_bound()
, upper_bound()
¶
constexpr std::optional<T> lower_bound() const noexcept;
constexpr std::optional<T> upper_bound() const noexcept;
std::nullopt
for empty intervals. Measures¶
(Requires std::is_arithmetic_v<T>
)
length()
¶
Returns \(b - a\). midpoint()
¶
Returns \((a + b) / 2\). Operations¶
intersect(const interval& other)
¶
Returns intersection. hull(const interval& other)
¶
Returns convex hull if intervals overlap or are adjacent, otherwise std::nullopt
. Operators¶
// Intersection
friend interval operator&(const interval& a, const interval& b);
// Comparison
friend auto operator<=>(const interval& a, const interval& b);
friend bool operator==(const interval& a, const interval& b);
// Stream output
friend std::ostream& operator<<(std::ostream& os, const interval& i);
Complete Example¶
See Getting Started and Examples for usage examples.