libzed 1.9.9
A general-purpose library for quick and simple data manipulation.
 
Loading...
Searching...
No Matches
refArray.hpp
1#pragma once
2
3#include <type_traits>
4
5#include "array.hpp"
6
7namespace z {
8namespace core {
16template <typename T>
17class refArray : public array<T> {
18private:
19 // only allow this class to work with pointers
20 static_assert(std::is_pointer<T>::value, "Template must be of pointer type.");
21
22protected:
23 virtual bool eq(const T &arg1, const T &arg2) const override {
24 return (arg1 == arg2) || (arg1 && arg2 && equals(*arg1, *arg2));
25 }
26
27 virtual bool gt(const T &arg1, const T &arg2) const override {
28 if (arg1 == arg2) {
29 return false;
30 } else if (arg1 && arg2) {
31 return greater(*arg1, *arg2);
32 } else {
33 return arg1;
34 }
35 }
36
37 virtual bool lt(const T &arg1, const T &arg2) const override {
38 if (arg1 == arg2) {
39 return false;
40 } else if (arg1 && arg2) {
41 return lesser(*arg1, *arg2);
42 } else {
43 return arg2;
44 }
45 }
46
47public:
50
60 template <typename... Args>
61 refArray(const T &arg1, const Args &...args) {
62 this->init(arg1, args...);
63 }
64
65 virtual bool operator()(const T &arg1, const T &arg2) const override {
66 return greater(*arg1, *arg2);
67 }
68};
69} // namespace core
70} // namespace z
A wrapper for std::vector.
Definition array.hpp:72
void init(const T &arg1)
Helper function for single object initialization.
Definition array.hpp:81
array()
Default constructor.
Definition array.hpp:146
An extension of the core::array class which assumes all elements to be pointers.
Definition refArray.hpp:17
virtual bool lt(const T &arg1, const T &arg2) const override
Check if one object is less than another.
Definition refArray.hpp:37
refArray()
Default constructor.
Definition refArray.hpp:49
virtual bool eq(const T &arg1, const T &arg2) const override
Check if two objects are equal.
Definition refArray.hpp:23
refArray(const T &arg1, const Args &...args)
List-initialized constructor.
Definition refArray.hpp:61
virtual bool gt(const T &arg1, const T &arg2) const override
Check if one object is greater than another.
Definition refArray.hpp:27
virtual bool operator()(const T &arg1, const T &arg2) const override
Callable operator.
Definition refArray.hpp:65