Boost logo

Geometry :

Subject: Re: [geometry] Run-Time specified geometries
From: Samuel Debionne (samuel.debionne_at_[hidden])
Date: 2013-10-24 10:48:07


> By the way, there are some custom solutions made by BG users,
> like here in brig project:
>
> https://code.google.com/p/brig/source/browse/boost/geometry.hpp

Thank you for the head up on BRIG.

>> The main difficulty I have encountered with dynamic
>> algorithms is that there are instantiated with every possible type the
>> variant can take. Some kind of filtering (e.g. types should have same
>> dimensions) using traits and tag dispatching must be in place within the
>> variant visitor. The other difficulty is with the return type that may
>> depends on the input types, but no meta function (think result_of) is
>> available.

> Yes, so all possible instances need to be available.

Is there a way with the current implementation to know what
specialization of an algorithm is available, i.e. which combinations of
template arguments (geometry types) do not lead to the MPL assert
NOT_OR_NOT_YET_IMPLEMENTED_FOR_THIS_GEOMETRY_TYPE ?

Right now I'm using my own MPL metafunction "is_implemented" in my
variant visitors but it's not very practical :

template <class GeometryOut>
struct intersection_visitor
    : public boost::static_visitor<void>
{
    intersection_visitor(GeometryOut& _out) : out_(_out) {}

    template <
        class Geometry1,
        class Geometry2
>
    struct is_implemented
    {
        typename boost::mpl::and_<
            typename boost::is_same<
                typename boost::geometry::tag<Geometry1>::type,
                typename boost::geometry::linestring_tag
        /* Add more meta programming here */
>::type
        type;
    };

    template <
        class Geometry1,
        class Geometry2
>
    void operator()(const Geometry1& _geom1, const Geometry2& _geom2,
typename boost::enable_if<typename is_implemented<Geometry1,
Geometry2>::type >::type* = 0) const
    {
        boost::geometry::intersection(_geom1, _geom2, out_);
    }

    template <
        class Geometry1,
        class Geometry2
>
    void operator()(const Geometry1& _geom1, const Geometry2& _geom,
typename boost::disable_if<typename is_implemented<Geometry1,
Geometry2>::type >::type* = 0) const
    {
        throw unimplemented_exception();
    }

    GeometryOut& out_;
};

Finally I'm wondering if SFINAE could be of any help...

Samuel


Geometry list run by mateusz at loskot.net