File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2828namespace CXXGraph {
2929template <typename T>
3030class 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);
3333template <typename T>
3434class 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
Original file line number Diff line number Diff line change @@ -51,7 +51,7 @@ void Node<T>::setId(const std::string &inpId) {
5151}
5252
5353template <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
6363template <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
7474template <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
7979template <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;
You can’t perform that action at this time.
0 commit comments