50 lines
1.0 KiB
C++
50 lines
1.0 KiB
C++
#pragma once
|
|
|
|
#include <concepts>
|
|
#include <exception>
|
|
#include <iterator>
|
|
#include <vector>
|
|
|
|
class Span
|
|
{
|
|
public:
|
|
Span() = delete;
|
|
Span(unsigned int size);
|
|
Span(const Span &other);
|
|
Span(Span &&other) noexcept;
|
|
Span &operator=(const Span &other);
|
|
Span &&operator=(Span &&other) noexcept;
|
|
~Span() noexcept;
|
|
|
|
void addNumber(int number);
|
|
|
|
unsigned int shortestSpan() const;
|
|
unsigned int longestSpan() const;
|
|
|
|
template <std::input_iterator Iterator>
|
|
requires std::same_as<std::iter_value_t<Iterator>, int>
|
|
void addRange(Iterator begin, Iterator end)
|
|
{
|
|
for (Iterator it = begin; it < end; it++)
|
|
{
|
|
addNumber(*it);
|
|
}
|
|
}
|
|
|
|
class OutOfSpaceException : public std::exception
|
|
{
|
|
public:
|
|
const char *what() const throw();
|
|
};
|
|
|
|
class NoSpanFoundException : public std::exception
|
|
{
|
|
public:
|
|
const char *what() const throw();
|
|
};
|
|
|
|
private:
|
|
unsigned int _size;
|
|
std::vector<int> _data;
|
|
};
|