-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContainer.h
executable file
·55 lines (40 loc) · 1.56 KB
/
Container.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#ifndef CONTAINER_H
#define CONTAINER_H
// Container.h
//
// UE Algorithmen und Datenstrukturen - SS 2016 Universitaet Wien
// Container - Projekt
// https://cewebs.cs.univie.ac.at/ADS/ss16/
#include <iostream>
#include <functional>
enum Order { dontcare, ascending, descending };
class ContainerException : public std::exception {
public:
virtual const char* what() const noexcept override = 0;
};
template <typename E>
class Container {
public:
Container& operator=(const Container&) = delete;
Container(const Container&) = delete;
Container() = default;
virtual ~Container() { }
virtual void add(const E& e) { add(&e, 1); }
virtual void add(const E e[], size_t s) = 0;
virtual void remove(const E& e) { remove(&e, 1); }
virtual void remove(const E e[], size_t s) = 0;
virtual bool member(const E& e) const = 0;
virtual size_t size() const = 0;
virtual bool empty() const { return size() == 0; }
virtual size_t apply(std::function<void(const E&)> f, Order order = dontcare) const = 0;
virtual E min() const = 0;
virtual E max() const = 0;
virtual size_t x() const = 0;
virtual std::ostream& print(std::ostream& o) const = 0;
};
template <typename E>
inline std::ostream& operator<<(std::ostream& o, const Container<E>& c) { return c.print(o); }
template <typename E> inline size_t hashValue(const E& e) { return size_t(e); }
template <typename E> inline double doubleValue(const E& e) { return double(e); }
template <typename E> inline size_t ordinalValue(const E& e) { return size_t(e); }
#endif //CONTAINER_H