Problems in adapting a geometry object model using boost geometry

  boost-geometry, c++

I tried to follow the example given by https://www.boost.org/doc/libs/1_75_0/libs/geometry/doc/html/geometry/examples/example__adapting_a_legacy_geometry_object_model.html for the following immutable pointerless variant.

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/register/linestring.hpp>
#include <boost/geometry/geometries/register/point.hpp>
#include <boost/range.hpp>
#include <vector>

class Point
{
 public:
   Point( double x, double y ) : m_x( x ), m_y( y ) {}
   double getX() const { return m_x; }
   double getY() const { return m_y; }

 private:
   double m_x, m_y;
};

using TyPoints = std::vector< Point >;


class LineString
{
 public:
   LineString( TyPoints points ) : m_points( std::move( points ) ) {}
   const TyPoints& getPoints() const { return m_points; }

 private:
   TyPoints m_points;
};


// Provide read only Boost.Range for LineString
namespace boost
{
   template<>
   struct range_const_iterator< LineString >
   {
      typedef std::vector< Point >::const_iterator type;
   };
}

inline std::vector< Point >::const_iterator range_begin( const LineString& ls )
{
   return ls.getPoints().cbegin();
}

inline std::vector< Point >::const_iterator

   range_end( const LineString& ls )
{
   return ls.getPoints().cend();
}

BOOST_GEOMETRY_REGISTER_POINT_2D_CONST( Point, double, cs::cartesian, getX(), getY() );
BOOST_GEOMETRY_REGISTER_LINESTRING( LineString );


int main( int argc, char* argv[] )
{
   const LineString lineString( { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 } } );

   boost::geometry::length( lineString );
   return 0;
}

However, registration as boost geometry fails and I do not know how to resolve this problems.

In file included from /usr/include/boost/geometry/core/closure.hpp:24,
                 from /usr/include/boost/geometry/geometry.hpp:25,
                 from /usr/include/boost/geometry.hpp:17,
                 from main.cpp:1:
/usr/include/boost/range/value_type.hpp: In instantiation of ‘struct boost::range_value<LineString>’:
/usr/include/boost/geometry/core/point_type.hpp:82:59:   required from ‘struct boost::geometry::core_dispatch::point_type<boost::geometry::linestring_tag, LineString>’
/usr/include/boost/geometry/core/coordinate_type.hpp:58:62:   required from ‘struct boost::geometry::core_dispatch::coordinate_type<boost::geometry::linestring_tag, LineString>’
/usr/include/boost/geometry/core/coordinate_type.hpp:92:25:   required from ‘struct boost::geometry::coordinate_type<LineString>’
/usr/include/boost/geometry/strategies/default_length_result.hpp:45:17:   required from ‘struct boost::geometry::resolve_strategy::default_length_result<LineString>’
/usr/include/boost/geometry/strategies/default_length_result.hpp:55:8:   required from ‘struct boost::geometry::resolve_variant::default_length_result<LineString>’
/usr/include/boost/geometry/strategies/default_length_result.hpp:82:8:   required from ‘struct boost::geometry::default_length_result<LineString>’
/usr/include/boost/geometry/algorithms/length.hpp:280:1:   required by substitution of ‘template<class Geometry> typename boost::geometry::default_length_result<Geometry>::type boost::geometry::length(const Geometry&) [with Geometry = LineString]’
main.cpp:62:40:   required from here
/usr/include/boost/range/value_type.hpp:26:12: error: no type named ‘type’ in ‘struct boost::range_iterator<LineString, void>’
   26 |     struct range_value : iterator_value< typename range_iterator<T>::type >
      |            ^~~~~~~~~~~
In file included from /usr/include/boost/geometry/core/coordinate_dimension.hpp:23,
                 from /usr/include/boost/geometry/geometry.hpp:26,
                 from /usr/include/boost/geometry.hpp:17,
                 from main.cpp:1:
/usr/include/boost/geometry/core/point_type.hpp: In instantiation of ‘struct boost::geometry::core_dispatch::point_type<boost::geometry::linestring_tag, LineString>’:
/usr/include/boost/geometry/core/coordinate_type.hpp:58:62:   required from ‘struct boost::geometry::core_dispatch::coordinate_type<boost::geometry::linestring_tag, LineString>’
/usr/include/boost/geometry/core/coordinate_type.hpp:92:25:   required from ‘struct boost::geometry::coordinate_type<LineString>’
/usr/include/boost/geometry/strategies/default_length_result.hpp:45:17:   required from ‘struct boost::geometry::resolve_strategy::default_length_result<LineString>’
/usr/include/boost/geometry/strategies/default_length_result.hpp:55:8:   required from ‘struct boost::geometry::resolve_variant::default_length_result<LineString>’
/usr/include/boost/geometry/strategies/default_length_result.hpp:82:8:   required from ‘struct boost::geometry::default_length_result<LineString>’
/usr/include/boost/geometry/algorithms/length.hpp:280:1:   required by substitution of ‘template<class Geometry> typename boost::geometry::default_length_result<Geometry>::type boost::geometry::length(const Geometry&) [with Geometry = LineString]’
main.cpp:62:40:   required from here
/usr/include/boost/geometry/core/point_type.hpp:82:59: error: no type named ‘type’ in ‘struct boost::range_value<LineString>’
   82 |     typedef typename boost::range_value<Linestring>::type type;
      |                                                           ^~~~
main.cpp: In function ‘int main(int, char**)’:
main.cpp:62:40: error: no matching function for call to ‘length(const LineString&)’
   62 |    boost::geometry::length( lineString );
      |                                        ^
In file included from /usr/include/boost/geometry/algorithms/detail/equals/implementation.hpp:38,
                 from /usr/include/boost/geometry/algorithms/equals.hpp:26,
                 from /usr/include/boost/geometry/algorithms/detail/buffer/get_piece_turns.hpp:21,
                 from /usr/include/boost/geometry/algorithms/detail/buffer/buffered_piece_collection.hpp:40,
                 from /usr/include/boost/geometry/algorithms/detail/buffer/buffer_inserter.hpp:34,
                 from /usr/include/boost/geometry/algorithms/buffer.hpp:41,
                 from /usr/include/boost/geometry/geometry.hpp:54,
                 from /usr/include/boost/geometry.hpp:17,
                 from main.cpp:1:
/usr/include/boost/geometry/algorithms/length.hpp:280:1: note: candidate: ‘template<class Geometry> typename boost::geometry::default_length_result<Geometry>::type boost::geometry::length(const Geometry&)’
  280 | length(Geometry const& geometry)
      | ^~~~~~
/usr/include/boost/geometry/algorithms/length.hpp:280:1: note:   substitution of deduced template arguments resulted in errors seen above
In file included from /usr/include/boost/geometry/algorithms/detail/equals/implementation.hpp:38,
                 from /usr/include/boost/geometry/algorithms/equals.hpp:26,
                 from /usr/include/boost/geometry/algorithms/detail/buffer/get_piece_turns.hpp:21,
                 from /usr/include/boost/geometry/algorithms/detail/buffer/buffered_piece_collection.hpp:40,
                 from /usr/include/boost/geometry/algorithms/detail/buffer/buffer_inserter.hpp:34,
                 from /usr/include/boost/geometry/algorithms/buffer.hpp:41,
                 from /usr/include/boost/geometry/geometry.hpp:54,
                 from /usr/include/boost/geometry.hpp:17,
                 from main.cpp:1:
/usr/include/boost/geometry/algorithms/length.hpp:306:1: note: candidate: ‘template<class Geometry, class Strategy> typename boost::geometry::default_length_result<Geometry>::type boost::geometry::length(const Geometry&, const Strategy&)’
  306 | length(Geometry const& geometry, Strategy const& strategy)
      | ^~~~~~
/usr/include/boost/geometry/algorithms/length.hpp:306:1: note:   template argument deduction/substitution failed:
main.cpp:62:40: note:   candidate expects 2 arguments, 1 provided
   62 |    boost::geometry::length( lineString );
      |                                        ^

Could please someone tell me how to fix this problem? Thank you very much!

Source: Windows Questions C++

LEAVE A COMMENT