// Boost.Geometry Index // // Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland. // // Use, modification and distribution is subject to the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_GEOMETRY_INDEX_EQUAL_TO_HPP #define BOOST_GEOMETRY_INDEX_EQUAL_TO_HPP #include namespace boost { namespace geometry { namespace index { namespace detail { template struct equals { static bool apply(Geometry const& g1, Geometry const& g2) { return geometry::equals(g1, g2); } }; template struct equals { static bool apply(T const& v1, T const& v2) { return v1 == v2; } }; template struct tuple_equals { inline static bool apply(Tuple const& t1, Tuple const& t2) { typedef typename boost::tuples::element::type T; return equals< T, typename geometry::traits::tag::type >::apply(boost::get(t1), boost::get(t2)) && tuple_equals::apply(t1, t2); } }; template struct tuple_equals { inline static bool apply(Tuple const&, Tuple const&) { return true; } }; } // namespace detail /*! \brief The function object comparing Values. It compares Geometries using geometry::equals() function. Other types are compared using operator==. The default version handles Values which are Indexables. This template is also specialized for std::pair and boost::tuple<...>. \tparam Value The type of objects which are compared by this function object. */ template struct equal_to { /*! \brief The type of result returned by function object. */ typedef bool result_type; /*! \brief Compare values. If Value is a Geometry geometry::equals() function is used. \param l First value. \param r Second value. \return true if values are equal. */ bool operator()(Value const& l, Value const& r) const { return detail::equals::type>::apply(l ,r); } }; /*! \brief The function object comparing Values. This specialization compares values of type std::pair. It compares pairs' first values, then second values. \tparam T1 The first type. \tparam T2 The second type. */ template struct equal_to< std::pair > { /*! \brief The type of result returned by function object. */ typedef bool result_type; /*! \brief Compare values. If pair<> Value member is a Geometry geometry::equals() function is used. \param l First value. \param r Second value. \return true if values are equal. */ bool operator()(std::pair const& l, std::pair const& r) const { typedef detail::equals::type> equals1; typedef detail::equals::type> equals2; return equals1::apply(l.first, r.first) && equals2::apply(l.second, r.second); } }; /*! \brief The function object comparing Values. This specialization compares values of type boost::tuple<...>. It compares all members of the tuple from the first one to the last one. */ template struct equal_to< boost::tuple > { typedef boost::tuple value_type; /*! \brief The type of result returned by function object. */ typedef bool result_type; /*! \brief Compare values. If tuple<> Value member is a Geometry geometry::equals() function is used. \param l First value. \param r Second value. \return true if values are equal. */ bool operator()(value_type const& l, value_type const& r) const { return detail::tuple_equals< value_type, 0, boost::tuples::length::value >::apply(l ,r); } }; }}} // namespace boost::geometry::index #if !defined(BOOST_NO_CXX11_HDR_TUPLE) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) #include namespace boost { namespace geometry { namespace index { namespace detail { template struct std_tuple_equals { inline static bool apply(Tuple const& t1, Tuple const& t2) { typedef typename std::tuple_element::type T; return equals< T, typename geometry::traits::tag::type >::apply(std::get(t1), std::get(t2)) && std_tuple_equals::apply(t1, t2); } }; template struct std_tuple_equals { inline static bool apply(Tuple const&, Tuple const&) { return true; } }; } // namespace detail /*! \brief The function object comparing Values. This specialization compares values of type std::tuple. It's defined if the compiler supports tuples and variadic templates. It compares all members of the tuple from the first one to the last one. */ template struct equal_to< std::tuple > { typedef std::tuple value_type; /*! \brief The type of result returned by function object. */ typedef bool result_type; /*! \brief Compare values. If tuple<> Value member is a Geometry geometry::equals() function is used. \param l First value. \param r Second value. \return true if values are equal. */ bool operator()(value_type const& l, value_type const& r) const { return detail::std_tuple_equals< value_type, 0, std::tuple_size::value >::apply(l ,r); } }; }}} // namespace boost::geometry::index #endif // !defined(BOOST_NO_CXX11_HDR_TUPLE) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) #endif // BOOST_GEOMETRY_INDEX_EQUAL_TO_HPP