Skip to content

Instantly share code, notes, and snippets.

@jedwardsol
Last active November 29, 2018 20:54
Show Gist options
  • Save jedwardsol/076e958639f7deb371a89b3860971151 to your computer and use it in GitHub Desktop.
Save jedwardsol/076e958639f7deb371a89b3860971151 to your computer and use it in GitHub Desktop.
Optional heuristic
struct Edge;
struct Vertex;
void enqueue(Edge *, double);
double someHeuristic(Vertex*, Vertex *);
// -----------------
#include <optional>
#include <functional>
using heuristic = std::function<double(Vertex*, Vertex*)>;
void singleFunction(Vertex* start, Vertex* end, std::optional<heuristic> heuristic=std::nullopt)
{
Edge *edge=nullptr;
double cost=10;
if (heuristic)
{
enqueue(edge, cost + (*heuristic)(start,end));
}
else
{
enqueue(edge, cost);
}
}
int main()
{
Vertex *start{nullptr};
Vertex *end {nullptr};
singleFunction(start,end);
singleFunction(start,end,someHeuristic);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment