diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 93061cfef..334424e55 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -2,9 +2,8 @@ name: CMake on: push: - branches: [ master ] pull_request: - branches: [ master ] + env: # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) BUILD_TYPE: Release @@ -58,5 +57,5 @@ jobs: working-directory: ${{github.workspace}}/build/test # Execute tests defined by the CMake configuration. # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail - run: ctest + run: ctest --output-on-failure diff --git a/.gitignore b/.gitignore index f982ca422..8d678b029 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,5 @@ packaging/ .vscode .code-workspace CXXGraph.code-workspace +# ignore Visual Studio files +/.vs diff --git a/include/CXXGraph/Edge/DirectedEdge.h b/include/CXXGraph/Edge/DirectedEdge.h index 76c8e5930..79e19b5b0 100755 --- a/include/CXXGraph/Edge/DirectedEdge.h +++ b/include/CXXGraph/Edge/DirectedEdge.h @@ -17,11 +17,11 @@ /*** License: MPL v2.0 ***/ /***********************************************************/ -#ifndef __CXXGRAPH_DIRECTEDEDGE_H__ -#define __CXXGRAPH_DIRECTEDEDGE_H__ +#ifndef CXXGRAPH_DIRECTEDEDGE_H +#define CXXGRAPH_DIRECTEDEDGE_H #pragma once #include "DirectedEdge_impl.hpp" -#endif // __CXXGRAPH_DIRECTEDEDGE_H__ +#endif // CXXGRAPH_DIRECTEDEDGE_H diff --git a/include/CXXGraph/Edge/DirectedEdge_decl.h b/include/CXXGraph/Edge/DirectedEdge_decl.h index b4611c3af..f33eabd1b 100644 --- a/include/CXXGraph/Edge/DirectedEdge_decl.h +++ b/include/CXXGraph/Edge/DirectedEdge_decl.h @@ -17,8 +17,8 @@ /*** License: MPL v2.0 ***/ /***********************************************************/ -#ifndef __CXXGRAPH_DIRECTEDEDGE_DECL_H__ -#define __CXXGRAPH_DIRECTEDEDGE_DECL_H__ +#ifndef CXXGRAPH_DIRECTEDEDGE_DECL_H_ +#define CXXGRAPH_DIRECTEDEDGE_DECL_H_ #pragma once @@ -42,19 +42,21 @@ std::ostream &operator<<(std::ostream &o, const DirectedEdge &edge); template class DirectedEdge : public Edge { public: - DirectedEdge(const CXXGraph::id_t id, const Node &node1, + constexpr DirectedEdge(const CXXGraph::id_t id, const Node &node1, const Node &node2); - DirectedEdge(const CXXGraph::id_t id, shared> node1, + constexpr DirectedEdge(const CXXGraph::id_t id, shared> node1, shared> node2); - DirectedEdge(const CXXGraph::id_t id, + constexpr DirectedEdge( + const CXXGraph::id_t id, const std::pair *, const Node *> &nodepair); - DirectedEdge( + constexpr DirectedEdge( const CXXGraph::id_t id, const std::pair>, shared>> &nodepair); - DirectedEdge(const Edge &edge); + constexpr DirectedEdge(const Edge &edge); virtual ~DirectedEdge() = default; - const Node &getFrom() const; - const Node &getTo() const; + constexpr const Node &getFrom() const; + constexpr const Node &getTo() const; + // const std::optional isDirected() const override; const std::optional isWeighted() const override; // operator @@ -67,4 +69,4 @@ class DirectedEdge : public Edge { }; } // namespace CXXGraph -#endif // __CXXGRAPH_DIRECTEDEDGE_H__ +#endif // CXXGRAPH_DIRECTEDEDGE_H_ diff --git a/include/CXXGraph/Edge/DirectedEdge_impl.hpp b/include/CXXGraph/Edge/DirectedEdge_impl.hpp index 9faa1a346..9bbf50e69 100644 --- a/include/CXXGraph/Edge/DirectedEdge_impl.hpp +++ b/include/CXXGraph/Edge/DirectedEdge_impl.hpp @@ -26,44 +26,42 @@ namespace CXXGraph { -using std::make_shared; -using std::make_unique; - template -DirectedEdge::DirectedEdge(const CXXGraph::id_t id, const Node &node1, +constexpr DirectedEdge::DirectedEdge(const CXXGraph::id_t id, + const Node &node1, const Node &node2) : Edge(id, node1, node2) {} template -DirectedEdge::DirectedEdge(const CXXGraph::id_t id, +constexpr DirectedEdge::DirectedEdge(const CXXGraph::id_t id, shared> node1, shared> node2) : Edge(id, node1, node2) {} template -DirectedEdge::DirectedEdge( +constexpr DirectedEdge::DirectedEdge( const CXXGraph::id_t id, const std::pair *, const Node *> &nodepair) : Edge(id, nodepair) {} template -DirectedEdge::DirectedEdge( +constexpr DirectedEdge::DirectedEdge( const CXXGraph::id_t id, const std::pair>, shared>> &nodepair) : Edge(id, nodepair) {} template -DirectedEdge::DirectedEdge(const Edge &edge) +constexpr DirectedEdge::DirectedEdge(const Edge &edge) : DirectedEdge(edge.getId(), *(edge.getNodePair().first), *(edge.getNodePair().second)) {} template -const Node &DirectedEdge::getFrom() const { +constexpr const Node &DirectedEdge::getFrom() const { return *(Edge::getNodePair().first); } template -const Node &DirectedEdge::getTo() const { +constexpr const Node &DirectedEdge::getTo() const { return *(Edge::getNodePair().second); } diff --git a/include/CXXGraph/Edge/DirectedWeightedEdge_decl.h b/include/CXXGraph/Edge/DirectedWeightedEdge_decl.h index e456c8ab4..ef3963f3e 100644 --- a/include/CXXGraph/Edge/DirectedWeightedEdge_decl.h +++ b/include/CXXGraph/Edge/DirectedWeightedEdge_decl.h @@ -31,7 +31,7 @@ using unique = std::unique_ptr; template using shared = std::shared_ptr; -// Foward Declaration +// Forward Declaration template class UndirectedWeightedEdge; @@ -45,23 +45,25 @@ std::ostream &operator<<(std::ostream &o, const DirectedWeightedEdge &edge); template class DirectedWeightedEdge : public DirectedEdge, public Weighted { public: - DirectedWeightedEdge(const CXXGraph::id_t id, const Node &node1, + constexpr DirectedWeightedEdge(const CXXGraph::id_t id, const Node &node1, const Node &node2, const double weight); - DirectedWeightedEdge(const CXXGraph::id_t id, shared> node1, + constexpr DirectedWeightedEdge(const CXXGraph::id_t id, + shared> node1, shared> node2, const double weight); - DirectedWeightedEdge( + constexpr DirectedWeightedEdge( const CXXGraph::id_t id, const std::pair *, const Node *> &nodepair, const double weight); - DirectedWeightedEdge( + constexpr DirectedWeightedEdge( const CXXGraph::id_t id, const std::pair>, shared>> &nodepair, const double weight); - DirectedWeightedEdge(const DirectedEdge &edge, const double weight); - DirectedWeightedEdge(const Edge &edge, const double weight); - DirectedWeightedEdge(const DirectedEdge &edge); - DirectedWeightedEdge(const Edge &edge); - DirectedWeightedEdge(const UndirectedWeightedEdge &edge); + constexpr DirectedWeightedEdge(const DirectedEdge &edge, + const double weight); + constexpr DirectedWeightedEdge(const Edge &edge, const double weight); + constexpr DirectedWeightedEdge(const DirectedEdge &edge); + constexpr DirectedWeightedEdge(const Edge &edge); + constexpr DirectedWeightedEdge(const UndirectedWeightedEdge &edge); virtual ~DirectedWeightedEdge() = default; const std::optional isWeighted() const override; // operator diff --git a/include/CXXGraph/Edge/DirectedWeightedEdge_impl.hpp b/include/CXXGraph/Edge/DirectedWeightedEdge_impl.hpp index 8bf19f073..3ba0aa105 100644 --- a/include/CXXGraph/Edge/DirectedWeightedEdge_impl.hpp +++ b/include/CXXGraph/Edge/DirectedWeightedEdge_impl.hpp @@ -26,57 +26,57 @@ namespace CXXGraph { -using std::make_shared; -using std::make_unique; - template -DirectedWeightedEdge::DirectedWeightedEdge(const CXXGraph::id_t id, +constexpr DirectedWeightedEdge::DirectedWeightedEdge(const CXXGraph::id_t id, const Node &node1, const Node &node2, const double weight) : DirectedEdge(id, node1, node2), Weighted(weight) {} template -DirectedWeightedEdge::DirectedWeightedEdge(const CXXGraph::id_t id, +constexpr DirectedWeightedEdge::DirectedWeightedEdge( + const CXXGraph::id_t id, shared> node1, shared> node2, const double weight) : DirectedEdge(id, node1, node2), Weighted(weight) {} template -DirectedWeightedEdge::DirectedWeightedEdge( +constexpr DirectedWeightedEdge::DirectedWeightedEdge( const CXXGraph::id_t id, const std::pair *, const Node *> &nodepair, const double weight) : DirectedEdge(id, nodepair), Weighted(weight) {} template -DirectedWeightedEdge::DirectedWeightedEdge( +constexpr DirectedWeightedEdge::DirectedWeightedEdge( const CXXGraph::id_t id, const std::pair>, shared>> &nodepair, const double weight) : DirectedEdge(id, nodepair), Weighted(weight) {} template -DirectedWeightedEdge::DirectedWeightedEdge(const DirectedEdge &edge, +constexpr DirectedWeightedEdge::DirectedWeightedEdge( + const DirectedEdge &edge, const double weight) : DirectedEdge(edge), Weighted(weight) {} template -DirectedWeightedEdge::DirectedWeightedEdge(const Edge &edge, +constexpr DirectedWeightedEdge::DirectedWeightedEdge(const Edge &edge, const double weight) : DirectedEdge(edge), Weighted(weight) {} template -DirectedWeightedEdge::DirectedWeightedEdge(const DirectedEdge &edge) +constexpr DirectedWeightedEdge::DirectedWeightedEdge( + const DirectedEdge &edge) : DirectedEdge(edge), Weighted() {} template -DirectedWeightedEdge::DirectedWeightedEdge(const Edge &edge) +constexpr DirectedWeightedEdge::DirectedWeightedEdge(const Edge &edge) : DirectedEdge(edge), Weighted() {} template -DirectedWeightedEdge::DirectedWeightedEdge( +constexpr DirectedWeightedEdge::DirectedWeightedEdge( const UndirectedWeightedEdge &edge) : DirectedEdge(edge), Weighted(edge.getWeight()) {} diff --git a/include/CXXGraph/Edge/Edge_decl.h b/include/CXXGraph/Edge/Edge_decl.h index 11d90d880..4f24053a7 100644 --- a/include/CXXGraph/Edge/Edge_decl.h +++ b/include/CXXGraph/Edge/Edge_decl.h @@ -49,17 +49,18 @@ class Edge { public: typedef T Node_t; - Edge(const CXXGraph::id_t id, const Node &node1, const Node &node2); - Edge(const CXXGraph::id_t id, shared> node1, + constexpr Edge(const CXXGraph::id_t id, const Node &node1, const Node &node2); + constexpr Edge(const CXXGraph::id_t id, shared> node1, shared> node2); - Edge(const CXXGraph::id_t id, + constexpr Edge(const CXXGraph::id_t id, const std::pair *, const Node *> &nodepair); - Edge(const CXXGraph::id_t id, + constexpr Edge( + const CXXGraph::id_t id, const std::pair>, shared>> &nodepair); virtual ~Edge() = default; void setFirstNode(shared> node); void setSecondNode(shared> node); - unsigned long long getId() const; + constexpr unsigned long long getId() const; const std::pair>, shared>> &getNodePair() const; shared> getOtherNode(shared> node) const; @@ -67,7 +68,7 @@ class Edge { virtual const std::optional isWeighted() const; // operator virtual bool operator==(const Edge &b) const; - bool operator<(const Edge &b) const; + constexpr bool operator<(const Edge &b) const; friend std::ostream &operator<< <>(std::ostream &os, const Edge &edge); }; diff --git a/include/CXXGraph/Edge/Edge_impl.hpp b/include/CXXGraph/Edge/Edge_impl.hpp index 7f35228b9..cd2f5b5c6 100644 --- a/include/CXXGraph/Edge/Edge_impl.hpp +++ b/include/CXXGraph/Edge/Edge_impl.hpp @@ -35,36 +35,30 @@ using std::make_shared; using std::make_unique; template -Edge::Edge(const CXXGraph::id_t id, const Node &node1, - const Node &node2) { - this->nodePair.first = make_shared>(node1); - this->nodePair.second = make_shared>(node2); - this->id = id; -} +constexpr Edge::Edge(const CXXGraph::id_t otherId, const Node &node1, + const Node &node2) + : id(otherId), nodePair{std::make_shared>(node1), + std::make_shared>(node2)} + {} template -Edge::Edge(const CXXGraph::id_t id, shared> node1, - shared> node2) { - this->nodePair.first = node1; - this->nodePair.second = node2; - this->id = id; -} +constexpr Edge::Edge(const CXXGraph::id_t otherId, shared> node1, + shared> node2) + : id(otherId), nodePair(node1, node2) {} template -Edge::Edge(const CXXGraph::id_t id, - const std::pair *, const Node *> &nodepair) { - this->nodePair.first = make_shared>(*(nodepair.first)); - this->nodePair.second = make_shared>(*(nodepair.second)); - this->id = id; -} +constexpr Edge::Edge(const CXXGraph::id_t otherId, + const std::pair *, const Node *> &nodepair) + : id(otherId) + , nodePair(std::make_shared>(*(nodepair.first)), + std::make_shared>(*(nodepair.second))) +{ } template -Edge::Edge( - const CXXGraph::id_t id, +constexpr Edge::Edge( + const CXXGraph::id_t otherId, const std::pair>, shared>> &nodepair) - : nodePair(nodepair) { - this->id = id; -} + : id(otherId), nodePair(nodepair) { } template void Edge::setFirstNode(shared> node) { @@ -79,7 +73,7 @@ void Edge::setSecondNode(shared> node) { } template -unsigned long long Edge::getId() const { +constexpr unsigned long long Edge::getId() const { return id; } @@ -114,7 +108,7 @@ bool Edge::operator==(const Edge &b) const { } template -bool Edge::operator<(const Edge &b) const { +constexpr bool Edge::operator<(const Edge &b) const { return (this->id < b.id); } diff --git a/include/CXXGraph/Edge/Weighted_decl.h b/include/CXXGraph/Edge/Weighted_decl.h index 6d6f97084..2b68d31ea 100644 --- a/include/CXXGraph/Edge/Weighted_decl.h +++ b/include/CXXGraph/Edge/Weighted_decl.h @@ -28,11 +28,11 @@ class Weighted { double weight = 0.0; public: - Weighted(); - explicit Weighted(const double weight); - virtual ~Weighted() = default; - double getWeight() const; - void setWeight(const double weight); + constexpr Weighted() noexcept; + constexpr explicit Weighted(const double weight) noexcept; + virtual ~Weighted() noexcept = default; + constexpr double getWeight() const noexcept; + constexpr void setWeight(const double weight); }; } // namespace CXXGraph diff --git a/include/CXXGraph/Edge/Weighted_impl.hpp b/include/CXXGraph/Edge/Weighted_impl.hpp index bcd7cda63..3b295b1eb 100644 --- a/include/CXXGraph/Edge/Weighted_impl.hpp +++ b/include/CXXGraph/Edge/Weighted_impl.hpp @@ -26,17 +26,16 @@ namespace CXXGraph { -// inline because the implementation of non-template function in header file -inline Weighted::Weighted() { weight = 0.0; } +constexpr Weighted::Weighted() noexcept : weight(0.0) {} -// inline because the implementation of non-template function in header file -inline Weighted::Weighted(const double weight) { this->weight = weight; } +constexpr Weighted::Weighted(const double inputWeight) noexcept + : weight(inputWeight) {} -// inline because the implementation of non-template function in header file -inline double Weighted::getWeight() const { return weight; } +constexpr double Weighted::getWeight() const noexcept { return weight; } -// inline because the implementation of non-template function in header file -inline void Weighted::setWeight(const double weight) { this->weight = weight; } +constexpr void Weighted::setWeight(const double inputWeight) { + weight = inputWeight; +} } // namespace CXXGraph diff --git a/include/CXXGraph/Graph/Graph_impl.hpp b/include/CXXGraph/Graph/Graph_impl.hpp index 950cd8daf..0bcba37d6 100644 --- a/include/CXXGraph/Graph/Graph_impl.hpp +++ b/include/CXXGraph/Graph/Graph_impl.hpp @@ -31,28 +31,21 @@ namespace CXXGraph { using std::make_shared; -using std::make_unique; template -Graph::Graph() { - /* Caching the adjacency matrix */ - cacheAdjMatrix(); - cacheDegreeMatrix(); - cacheLaplacianMatrix(); - cacheTransitionMatrix(); -} +Graph::Graph() + : cachedAdjMatrix(Graph::getAdjMatrix()), + cachedDegreeMatrix(Graph::getDegreeMatrix()), + cachedLaplacianMatrix(Graph::getLaplacianMatrix()), + cachedTransitionMatrix(Graph::getTransitionMatrix()) {} template -Graph::Graph(const T_EdgeSet &edgeSet) { - for (auto edgeIt : edgeSet) { - this->edgeSet.insert(edgeIt); - } - /* Caching the adjacency matrix */ - cacheAdjMatrix(); - cacheDegreeMatrix(); - cacheLaplacianMatrix(); - cacheTransitionMatrix(); -} +Graph::Graph(const T_EdgeSet &edgeSetToCopy) + : edgeSet(edgeSetToCopy), + cachedAdjMatrix(Graph::getAdjMatrix()), + cachedDegreeMatrix(Graph::getDegreeMatrix()), + cachedLaplacianMatrix(Graph::getLaplacianMatrix()), + cachedTransitionMatrix(Graph::getTransitionMatrix()) {} template const T_EdgeSet &Graph::getEdgeSet() const { diff --git a/include/CXXGraph/Node/Node_decl.h b/include/CXXGraph/Node/Node_decl.h index 65edf1fb7..1668a0240 100644 --- a/include/CXXGraph/Node/Node_decl.h +++ b/include/CXXGraph/Node/Node_decl.h @@ -22,38 +22,39 @@ #pragma once #include - +#include #include "CXXGraph/Utility/id_t.hpp" namespace CXXGraph { -template +template class Node; -template -std::ostream &operator<<(std::ostream &os, const Node &node); -template +template +std::ostream &operator<<(std::ostream &os, const Node &node); +template class Node { private: CXXGraph::id_t id = 0; - std::string userId = ""; + UserID userId{}; T data; - void setId(const std::string &); + constexpr void setId(const UserID &); public: - typedef T Node_t; + using Node_t = T; - Node(const std::string &, const T &data); + constexpr Node(const UserID &, const T &data); // Move constructor - explicit Node(const std::string &, T &&data) noexcept; - ~Node() = default; - const CXXGraph::id_t &getId() const; - const std::string &getUserId() const; - const T &getData() const; - T& getData(); - void setData(T &&new_data); + constexpr explicit Node(const UserID &, T &&data) noexcept(std::is_nothrow_move_assignable::value); + ~Node() noexcept = default; + constexpr const CXXGraph::id_t &getId() const; + constexpr const UserID &getUserId() const; + constexpr const T &getData() const; + constexpr T& getData(); + constexpr void setData(T &&new_data); // operator - bool operator==(const Node &b) const; - bool operator<(const Node &b) const; - friend std::ostream &operator<< <>(std::ostream &os, const Node &node); + constexpr bool operator==(const Node &b) const; + constexpr bool operator<(const Node &b) const; + + friend std::ostream &operator<< <>(std::ostream &os, const Node &node); }; } // namespace CXXGraph diff --git a/include/CXXGraph/Node/Node_impl.hpp b/include/CXXGraph/Node/Node_impl.hpp index 058f092ef..3ff1f85c2 100644 --- a/include/CXXGraph/Node/Node_impl.hpp +++ b/include/CXXGraph/Node/Node_impl.hpp @@ -20,76 +20,122 @@ #ifndef __CXXGRAPH_NODE_IMPL_H__ #define __CXXGRAPH_NODE_IMPL_H__ +#if __cplusplus >= 202004L +#include +#else +#include +#endif + #include +#include +#include #include "Node_decl.h" namespace CXXGraph { +// internals not intended to be accessed by the end user +namespace internals { +template +constexpr CXXGraph::id_t UserIdToId(const AnyUserID &id) { + // in C++ 23 we have constexpr hashes + if constexpr (__cplusplus >= 202302L) return std::hash{}(id); + // hashing is trivial for integral types + if constexpr (std::is_integral::value) { + // assert nothing is greater than a size_t to avoid issues with GCC and + // clang's 128 bit ints, a size_t is usually 64 bits + static_assert(std::numeric_limits::max() >= + std::numeric_limits::max()); + + if constexpr (std::is_signed::value) { + // Add id to half max so that we have something unique + return (std::numeric_limits::max() / 2) + id; + } + return static_cast(id); + } + // typepun the float into an int + if constexpr (std::is_floating_point::value) { + // static assert to avoid long double (80 bits rather than 64) + static_assert(sizeof(CXXGraph::id_t) >= sizeof(AnyUserID)); +// In C++20 we can do typepunning at compile time +#if __cplusplus >= 202004L + return std::bit_cast(id); +#else // < C++20 + // otherwise use memcpy (not compile time) + CXXGraph::id_t result{}; + std::memcpy(&result, &id, sizeof(id)); + return result; +#endif // >= C++20 + } + // resort back to runtime hash + return std::hash{}(id); +} +} // namespace internals -template +template class Node; -template -Node::Node(const std::string &id, const T &data) { - this->userId = id; - // the userid is set as sha512 hash of the user provided id - setId(id); - this->data = data; +template +constexpr Node::Node(const UserID &otherId, const T &otherData) + : id(internals::UserIdToId(otherId)), userId(otherId), data(otherData) { + static_assert( + !std::is_pointer::value, + "Pointer is not allowed as an ID type, did you mean std::string?"); } -template -Node::Node(const std::string &id, T &&data) noexcept { - this->userId = id; - // the userid is set as sha512 hash of the user provided id - setId(id); - this->data = std::move(data); +template +constexpr Node::Node(const UserID &otherId, T &&otherData) noexcept( + std::is_nothrow_move_assignable::value) + : id(internals::UserIdToId(otherId)), userId(otherId), data(otherData) { + static_assert( + !std::is_pointer::value, + "Pointer is not allowed as an ID type, did you mean std::string?"); } -template -void Node::setId(const std::string &inpId) { - this->id = std::hash{}(inpId); +template +constexpr void Node::setId(const UserID &inputId) { + this->id = UserIdToId(inputId); } -template -const CXXGraph::id_t &Node::getId() const { +template +constexpr const CXXGraph::id_t &Node::getId() const { return id; } -template -const std::string &Node::getUserId() const { +template +constexpr const UserID &Node::getUserId() const { return userId; } -template -const T &Node::getData() const { +template +constexpr const T &Node::getData() const { return data; } -template -T &Node::getData() { +template +constexpr T &Node::getData() { return data; } -template -void Node::setData(T &&new_data) { +template +constexpr void Node::setData(T &&new_data) { this->data = std::move(new_data); } // The data type T must have an overload of the equality operator -template -bool Node::operator==(const Node &b) const { +template +constexpr bool Node::operator==(const Node &b) const { return (this->id == b.id && this->data == b.data); } -template -bool Node::operator<(const Node &b) const { +template +constexpr bool Node::operator<(const Node &b) const { return (this->id < b.id); } // ostream overload // The data type T must have an overload of the ostream operator -template -std::ostream &operator<<(std::ostream &os, const Node &node) { +template +std::ostream &operator<<(std::ostream &os, const Node &node) { os << "Node: {\n" << " Id:\t" << node.userId << "\n Data:\t" << node.data << "\n}"; return os; diff --git a/include/CXXGraph/Utility/Typedef.hpp b/include/CXXGraph/Utility/Typedef.hpp index d255184ac..ad7779d27 100644 --- a/include/CXXGraph/Utility/Typedef.hpp +++ b/include/CXXGraph/Utility/Typedef.hpp @@ -36,7 +36,7 @@ namespace CXXGraph { template using shared = std::shared_ptr; -template +template class Node; template diff --git a/test/ConstexprTests.cpp b/test/ConstexprTests.cpp new file mode 100644 index 000000000..061ba7780 --- /dev/null +++ b/test/ConstexprTests.cpp @@ -0,0 +1,26 @@ + +#include + +#include "CXXGraph/CXXGraph.hpp" +#include "gtest/gtest.h" + +// Boolean results will always be true +// functions are only here to test that this compiles +constexpr bool IsConstexprContextCreateable() { + CXXGraph::Node node1(1, 1); + return true; +} + +constexpr bool IsConstexprCreateable() { + constexpr CXXGraph::Node node1(1, 1); + return true; +} + + +TEST(ConstexprTests, IsConstexprContextCreateable) { + ASSERT_TRUE(IsConstexprContextCreateable()); +} + +TEST(ConstexprTests, IsConstexprCreateable) { + ASSERT_TRUE(IsConstexprCreateable()); +} \ No newline at end of file