From da2386585da4f7e72e359a1334ce4b78c8892caa Mon Sep 17 00:00:00 2001 From: Justin Viiret Date: Fri, 30 Oct 2015 09:52:49 +1100 Subject: [PATCH] Init filter members to nullptr Note that BGL filters must be default-constructible. --- src/nfagraph/ng_depth.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/nfagraph/ng_depth.cpp b/src/nfagraph/ng_depth.cpp index 719c7654..d7945be9 100644 --- a/src/nfagraph/ng_depth.cpp +++ b/src/nfagraph/ng_depth.cpp @@ -55,14 +55,14 @@ namespace ue2 { namespace { /** Distance value used to indicate that the vertex can't be reached. */ -static const int DIST_UNREACHABLE = INT_MAX; +static constexpr int DIST_UNREACHABLE = INT_MAX; /** * Distance value used to indicate that the distance to a vertex is infinite * (for example, it's the max distance and there's a cycle in the path) or so * large that we should consider it effectively infinite. */ -static const int DIST_INFINITY = INT_MAX - 1; +static constexpr int DIST_INFINITY = INT_MAX - 1; // // Filters @@ -71,10 +71,12 @@ static const int DIST_INFINITY = INT_MAX - 1; template struct NodeFilter { typedef typename GraphT::edge_descriptor EdgeT; - NodeFilter() { } + NodeFilter() {} // BGL filters must be default-constructible. NodeFilter(const vector *bad_in, const GraphT *g_in) : bad(bad_in), g(g_in) { } bool operator()(const EdgeT &e) const { + assert(g && bad); + u32 src_idx = (*g)[source(e, *g)].index; u32 tar_idx = (*g)[target(e, *g)].index; @@ -84,16 +86,20 @@ struct NodeFilter { return !(*bad)[src_idx] && !(*bad)[tar_idx]; } - const vector *bad; - const GraphT *g; + +private: + const vector *bad = nullptr; + const GraphT *g = nullptr; }; template struct StartFilter { typedef typename GraphT::edge_descriptor EdgeT; - StartFilter() { } + StartFilter() {} // BGL filters must be default-constructible. explicit StartFilter(const GraphT *g_in) : g(g_in) { } bool operator()(const EdgeT &e) const { + assert(g); + u32 src_idx = (*g)[source(e, *g)].index; u32 tar_idx = (*g)[target(e, *g)].index; @@ -107,7 +113,9 @@ struct StartFilter { } return true; } - const GraphT *g; + +private: + const GraphT *g = nullptr; }; } // namespace