Skip to content

Commit

Permalink
Use gz::utils::NeverDestroyed
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Peters <[email protected]>
  • Loading branch information
scpeters committed Jul 31, 2024
1 parent 051b74f commit 3fa9854
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 4 additions & 3 deletions include/gz/math/graph/Edge.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
#include <set>

#include <gz/math/config.hh>
#include "gz/math/graph/Vertex.hh"
#include <gz/math/graph/Vertex.hh>
#include <gz/utils/NeverDestroyed.hh>

namespace gz::math
{
Expand Down Expand Up @@ -342,9 +343,9 @@ namespace graph
template<typename E, typename EdgeType>
EdgeType &NullEdge()
{
static EdgeType e(
static gz::utils::NeverDestroyed<EdgeType> e(
VertexId_P(kNullId, kNullId), E(), 1.0, kNullId);
return e;
return e.Access();
}
} // namespace graph
} // namespace GZ_MATH_VERSION_NAMESPACE
Expand Down
5 changes: 3 additions & 2 deletions include/gz/math/graph/Vertex.hh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <gz/math/config.hh>
#include <gz/math/Helpers.hh>
#include <gz/utils/NeverDestroyed.hh>

namespace gz::math
{
Expand Down Expand Up @@ -143,8 +144,8 @@ namespace graph
template<typename V>
Vertex<V> &NullVertex()
{
static Vertex<V> v("__null__", V(), kNullId);
return v;
static gz::utils::NeverDestroyed<Vertex<V>> v("__null__", V(), kNullId);
return v.Access();
}

/// \def VertexRef_M
Expand Down

0 comments on commit 3fa9854

Please sign in to comment.