#include <boost\graph\adjacency_list.hpp>
#include <boost\graph\astar_search.hpp>
#include <cassert>
#include <iostream>

typedef boost::adjacency_list<boost::listS, boost::vecS, boost::directedS> mygraph_t;


struct Goal_Found_Ex {};

template<class Vertex>
struct astar_vis : public boost::default_astar_visitor
{
    astar_vis(Vertex goal)
		: m_goal(goal)
	{ }

	template<typename Graph>
	void examine_vertex(Vertex v, Graph const& g)
	{
		if ( v == m_goal )
			throw Goal_Found_Ex();
	}

	Vertex m_goal;
};

int main()
{
	mygraph_t graph;

	mygraph_t::vertex_descriptor aVertex = boost::add_vertex(graph);
	mygraph_t::vertex_descriptor bVertex = boost::add_vertex(graph);

	mygraph_t::edge_descriptor edge; bool success;
	boost::tie(edge, success) = boost::add_edge(aVertex, bVertex, graph);
	assert(success);


	try {
		boost::astar_search(graph, aVertex, boost::astar_heuristic<mygraph_t, double>(), 
			boost::visitor(astar_vis<mygraph_t::vertex_descriptor>(aVertex)));
	}
	catch(Goal_Found_Ex gf)
	{
		gf;
		std::cout << "Way found" << std::endl;
		return 0x0;
	}

	std::cout << "Way not found" << std::endl;
	return 0x1;
}
