Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.


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


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.


template<typename Tag, typename ... BaseTags>
struct tag_cast
  // ...

Template parameter(s)



typename Tag

The tag to be casted to one of the base tags

typename ... BaseTags

Base tags



#include <boost/geometry.hpp>


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

[Note] 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] 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.


Compile time


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()
    typedef geo::model::d2::point_xy<double> point_type;
    typedef geo::model::polygon<point_type> polygon_type;

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

    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