ORIGINAL
Loading...
Searching...
No Matches
couple.h
1#ifndef COUPLE_H
2#define COUPLE_H
3
4#include "printable.h"
5
6namespace original
7{
8 template<typename F_TYPE, typename S_TYPE>
9 class couple final : public printable
10 {
11 F_TYPE first_;
12 S_TYPE second_;
13 public:
14 explicit couple();
15 couple(F_TYPE* first, S_TYPE* second);
16 couple(const F_TYPE& first, const S_TYPE& second);
17 couple(const couple& other);
18 couple& operator=(const couple& other);
19 bool operator==(const couple& other) const;
20 F_TYPE& first();
21 S_TYPE& second();
22 ~couple() override;
23 [[nodiscard]] std::string className() const override;
24 [[nodiscard]] std::string toString(bool enter) const override;
25 };
26}
27
28 template <typename F_TYPE, typename S_TYPE>
29 original::couple<F_TYPE, S_TYPE>::couple() : first_(), second_() {}
30
31 template <typename F_TYPE, typename S_TYPE>
32 original::couple<F_TYPE, S_TYPE>::couple(F_TYPE* first, S_TYPE* second)
33 : first_(*first), second_(*second) {}
34
35 template <typename F_TYPE, typename S_TYPE>
36 original::couple<F_TYPE, S_TYPE>::couple(const F_TYPE& first, const S_TYPE& second)
37 : first_(first), second_(second) {}
38
39 template <typename F_TYPE, typename S_TYPE>
40 original::couple<F_TYPE, S_TYPE>::couple(const couple& other)
41 : first_(other.first_), second_(other.second_) {}
42
43 template <typename F_TYPE, typename S_TYPE>
44 auto original::couple<F_TYPE, S_TYPE>::operator=(const couple& other) -> couple&
45 {
46 if (this == &other) return *this;
47 first_ = other.first_;
48 second_ = other.second_;
49 return *this;
50 }
51
52 template <typename F_TYPE, typename S_TYPE>
53 auto original::couple<F_TYPE, S_TYPE>::operator==(const couple& other) const -> bool
54 {
55 return first_ == other.first_ && second_ == other.second_;
56 }
57
58 template <typename F_TYPE, typename S_TYPE>
59 auto original::couple<F_TYPE, S_TYPE>::first() -> F_TYPE&
60 {
61 return this->first_;
62 }
63
64 template <typename F_TYPE, typename S_TYPE>
65 auto original::couple<F_TYPE, S_TYPE>::second() -> S_TYPE&
66 {
67 return this->second_;
68 }
69
70 template <typename F_TYPE, typename S_TYPE>
71 original::couple<F_TYPE, S_TYPE>::~couple() = default;
72
73 template <typename F_TYPE, typename S_TYPE>
74 auto original::couple<F_TYPE, S_TYPE>::className() const -> std::string
75 {
76 return "couple";
77 }
78
79 template <typename F_TYPE, typename S_TYPE>
80 auto original::couple<F_TYPE, S_TYPE>::toString(const bool enter) const -> std::string
81 {
82 std::stringstream ss;
83 ss << this->className() << "(" << "first: " << formatString(this->first_)
84 << ", " << "second: " << formatString(this->second_) << ")";
85 if (enter) ss << "\n";
86 return ss.str();
87 }
88
89#endif //COUPLE_H
Definition couple.h:10
Definition printable.h:9