Skip to content

Commit 4e30cc5

Browse files
OlekRaymondJustCallMeRay
authored andcommitted
Added constexpr to some functions
1 parent 1804b50 commit 4e30cc5

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

include/CXXGraph/Node/Node_decl.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
namespace CXXGraph {
2929
template <typename T>
3030
class Node;
31-
template <typename T>
32-
std::ostream &operator<<(std::ostream &os, const Node<T> &node);
31+
template <typename T, typename Stream>
32+
constexpr Stream &operator<<(Stream &os, const Node<T> &node);
3333
template <typename T>
3434
class Node {
3535
private:
@@ -39,7 +39,7 @@ class Node {
3939
void setId(const std::string &);
4040

4141
public:
42-
typedef T Node_t;
42+
using Node_t = T;
4343

4444
Node(const std::string &, const T &data);
4545
// Move constructor
@@ -52,7 +52,8 @@ class Node {
5252
// operator
5353
bool operator==(const Node<T> &b) const;
5454
bool operator<(const Node<T> &b) const;
55-
friend std::ostream &operator<< <>(std::ostream &os, const Node<T> &node);
55+
template<typename Stream>
56+
friend Stream &operator<< <>(Stream &os, const Node<T> &node);
5657
};
5758

5859
} // namespace CXXGraph

include/CXXGraph/Node/Node_impl.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void Node<T>::setId(const std::string &inpId) {
5151
}
5252

5353
template <typename T>
54-
const CXXGraph::id_t &Node<T>::getId() const {
54+
constexpr const CXXGraph::id_t &Node<T>::getId() const {
5555
return id;
5656
}
5757

@@ -61,7 +61,7 @@ const std::string &Node<T>::getUserId() const {
6161
}
6262

6363
template <typename T>
64-
const T &Node<T>::getData() const {
64+
constexpr const T &Node<T>::getData() const {
6565
return data;
6666
}
6767

@@ -72,19 +72,19 @@ void Node<T>::setData(T &&new_data) {
7272

7373
// The data type T must have an overload of the equality operator
7474
template <typename T>
75-
bool Node<T>::operator==(const Node<T> &b) const {
75+
constexpr bool Node<T>::operator==(const Node<T> &b) const {
7676
return (this->id == b.id && this->data == b.data);
7777
}
7878

7979
template <typename T>
80-
bool Node<T>::operator<(const Node<T> &b) const {
80+
constexpr bool Node<T>::operator<(const Node<T> &b) const {
8181
return (this->id < b.id);
8282
}
8383

8484
// ostream overload
8585
// The data type T must have an overload of the ostream operator
86-
template <typename T>
87-
std::ostream &operator<<(std::ostream &os, const Node<T> &node) {
86+
template <typename T, typename Stream>
87+
constexpr Stream &operator<<(Stream &os, const Node<T> &node) {
8888
os << "Node: {\n"
8989
<< " Id:\t" << node.userId << "\n Data:\t" << node.data << "\n}";
9090
return os;

0 commit comments

Comments
 (0)