// Boost.Geometry Index // // Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland. // // This file was modified by Oracle on 2019, 2020. // Modifications copyright (c) 2019-2020 Oracle and/or its affiliates. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle // // 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_UTIL_TUPLES_HPP #define BOOST_GEOMETRY_UTIL_TUPLES_HPP #include #include #include #include #include #include #include #ifdef BOOST_GEOMETRY_CXX11_TUPLE #include #endif // BOOST_GEOMETRY_CXX11_TUPLE namespace boost { namespace geometry { namespace tuples { using boost::tuples::null_type; template struct element : boost::tuples::element {}; template struct size : boost::tuples::length {}; template inline typename boost::tuples::access_traits < typename boost::tuples::element >::type >::non_const_type get(boost::tuples::cons & tup) { return boost::tuples::get(tup); } template inline typename boost::tuples::access_traits < typename boost::tuples::element >::type >::const_type get(boost::tuples::cons const& tup) { return boost::tuples::get(tup); } template struct element > {}; template struct element<0, std::pair > { typedef F type; }; template struct element<1, std::pair > { typedef S type; }; template struct size > : boost::integral_constant {}; template struct get_pair; template struct get_pair<0, std::pair > { typedef F type; static inline F& apply(std::pair & p) { return p.first; } static inline F const& apply(std::pair const& p) { return p.first; } }; template struct get_pair<1, std::pair > { typedef S type; static inline S& apply(std::pair & p) { return p.second; } static inline S const& apply(std::pair const& p) { return p.second; } }; template inline typename get_pair >::type& get(std::pair & p) { return get_pair >::apply(p); } template inline typename get_pair >::type const& get(std::pair const& p) { return get_pair >::apply(p); } #ifdef BOOST_GEOMETRY_CXX11_TUPLE template struct element > : std::tuple_element > {}; template struct size > : std::tuple_size > {}; template inline typename std::tuple_element >::type& get(std::tuple & tup) { return std::get(tup); } template inline typename std::tuple_element >::type const& get(std::tuple const& tup) { return std::get(tup); } #endif // BOOST_GEOMETRY_CXX11_TUPLE // find_index_if // Searches for the index of an element for which UnaryPredicate returns true // If such element is not found the result is N template < typename Tuple, template class UnaryPred, int I = 0, int N = size::value > struct find_index_if : boost::mpl::if_c < UnaryPred::type>::value, boost::integral_constant, typename find_index_if::type >::type {}; template < typename Tuple, template class UnaryPred, int N > struct find_index_if : boost::integral_constant {}; // find_if // Searches for an element for which UnaryPredicate returns true // If such element is not found the result is boost::tuples::null_type template < typename Tuple, template class UnaryPred, int I = 0, int N = size::value > struct find_if : boost::mpl::if_c < UnaryPred::type>::value, element, find_if >::type {}; template < typename Tuple, template class UnaryPred, int N > struct find_if { typedef boost::tuples::null_type type; }; // is_found // Returns true if a type T (the result of find_if) was found. template struct is_found : boost::mpl::not_ > {}; // is_not_found // Returns true if a type T (the result of find_if) was not found. template struct is_not_found : boost::is_same {}; // exists_if // Returns true if search for element meeting UnaryPred can be found. template class UnaryPred> struct exists_if : is_found::type> {}; // push_back // A utility used to create a type/object of a Tuple containing // all types/objects stored in another Tuple plus additional one. template ::value> struct push_back_bt { typedef boost::tuples::cons< typename element::type, typename push_back_bt::type > type; static type apply(Tuple const& tup, T const& t) { return type( geometry::tuples::get(tup), push_back_bt::apply(tup, t) ); } }; template struct push_back_bt { typedef boost::tuples::cons type; static type apply(Tuple const&, T const& t) { return type(t, boost::tuples::null_type()); } }; template struct push_back : push_back_bt {}; template struct push_back, T> { #ifdef BOOST_GEOMETRY_CXX11_TUPLE typedef std::tuple type; #else typedef boost::tuple type; #endif // BOOST_GEOMETRY_CXX11_TUPLE static type apply(std::pair const& p, T const& t) { return type(p.first, p.second, t); } #ifdef BOOST_GEOMETRY_CXX11_TUPLE #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) static type apply(std::pair && p, T const& t) { return type(std::move(p.first), std::move(p.second), t); } static type apply(std::pair && p, T && t) { return type(std::move(p.first), std::move(p.second), std::move(t)); } #endif #endif // BOOST_GEOMETRY_CXX11_TUPLE }; #ifdef BOOST_GEOMETRY_CXX11_TUPLE // NOTE: In C++14 std::integer_sequence and std::make_integer_sequence could be used template struct int_sequence {}; template struct make_int_sequence { typedef typename make_int_sequence::type type; }; template struct make_int_sequence<0, Is...> { typedef int_sequence type; }; template struct push_back_st; template struct push_back_st, std::tuple, T> { typedef std::tuple type; static type apply(std::tuple const& tup, T const& t) { return type(std::get(tup)..., t); } #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) static type apply(std::tuple && tup, T const& t) { return type(std::move(std::get(tup))..., t); } static type apply(std::tuple && tup, T && t) { return type(std::move(std::get(tup))..., std::move(t)); } #endif }; template struct push_back, T> : push_back_st < typename make_int_sequence::type, std::tuple, T > {}; #endif // BOOST_GEOMETRY_CXX11_TUPLE }}} // namespace boost::geometry::tuples #endif // BOOST_GEOMETRY_UTIL_TUPLES_HPP