| Home | Libraries | People | FAQ | More

#### tag_cast

Metafunction defining a type being either the specified tag, or one of the specified basetags if the type inherits from them.

###### Description

Tags can inherit each other. A multi_point inherits, for example, both the multi_tag and the pointlike_tag. Often behaviour can be shared between different geometry types. A tag, found by the metafunction tag, can be casted to a more basic tag, and then dispatched by that tag.

###### Synopsis

    template<typename Tag, typename ... BaseTags>
    struct tag_cast
    {
      // ...
    };

###### Template parameter(s)

Parameter | Description
--- | ---
typename Tag | The tag to be casted to one of the base tags
typename ... BaseTags | Base tags

###### Header

Either

`#include <boost/geometry.hpp>`

Or

`#include <boost/geometry/core/tag_cast.hpp>`

| Note
The specified tag list is handled in the specified order: as soon as a tag inheriting the specified tag is found, it is defined as the metafunction typedef type.

| Note
If none of the specified possible base tags is a base class of the specified tag, the tag itself is defined as the type result of the metafunction.

###### Complexity

Compile time

###### Example

Check if the polygon_tag can be casted to the areal_tag

    #include <iostream>
    #include <typeinfo>

    #include <boost/geometry.hpp>
    #include <boost/geometry/geometries/polygon.hpp>
    #include <boost/geometry/geometries/point_xy.hpp>

    namespace geo = boost::geometry;
    int main()
    {
        using point_type = geo::model::d2::point_xy<double>;
        using polygon_type = geo::model::polygon<point_type>;

        using tag = geo::tag<polygon_type>::type;
        using base_tag = geo::tag_cast<tag, geo::linear_tag, geo::areal_tag>::type;

        std::cout << "tag: " << typeid(tag).name() << std::endl
            << "base tag: " << typeid(base_tag).name() << std::endl;

        return 0;
    }

Output (in MSVC):

    tag: struct boost::geometry::polygon_tag
    base tag: struct boost::geometry::areal_tag