// 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 namespace boost { namespace geometry { namespace tuples { template struct is_tuple : std::integral_constant {}; template struct is_tuple> : std::integral_constant {}; template struct is_tuple> : std::integral_constant {}; template struct is_tuple> : std::integral_constant {}; template struct is_tuple> : std::integral_constant {}; template struct element; template struct element> : std::tuple_element> {}; template struct element> : std::tuple_element> {}; template struct element> { typedef typename boost::tuples::element < I, boost::tuples::tuple >::type type; }; template struct element> { typedef typename boost::tuples::element < I, boost::tuples::cons >::type type; }; template struct size; template struct size> : std::tuple_size> {}; template struct size> : std::tuple_size> {}; template struct size> : std::integral_constant < std::size_t, boost::tuples::length>::value > {}; template struct size> : std::integral_constant < std::size_t, boost::tuples::length>::value > {}; template constexpr inline typename std::tuple_element>::type& get(std::tuple & t) { return std::get(t); } template constexpr inline typename std::tuple_element>::type const& get(std::tuple const& t) { return std::get(t); } template constexpr inline typename std::tuple_element>::type& get(std::pair & t) { return std::get(t); } template constexpr inline typename std::tuple_element>::type const& get(std::pair const& t) { return std::get(t); } template inline typename boost::tuples::access_traits < typename boost::tuples::element>::type >::non_const_type get(boost::tuples::tuple & t) { return boost::tuples::get(t); } template inline typename boost::tuples::access_traits < typename boost::tuples::element>::type >::const_type get(boost::tuples::tuple const& t) { return boost::tuples::get(t); } 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); } // 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, std::size_t I = 0, std::size_t N = size::value > struct find_index_if : std::conditional_t < UnaryPred::type>::value, std::integral_constant, typename find_index_if::type > {}; template < typename Tuple, template class UnaryPred, std::size_t N > struct find_index_if : std::integral_constant {}; // find_if // Searches for an element for which UnaryPredicate returns true // If such element is not found the result is detail::null_type namespace detail { struct null_type {}; } // detail template < typename Tuple, template class UnaryPred, std::size_t I = 0, std::size_t N = size::value > struct find_if : std::conditional_t < UnaryPred::type>::value, element, find_if > {}; template < typename Tuple, template class UnaryPred, std::size_t N > struct find_if { typedef detail::null_type type; }; // is_found // Returns true if a type T (the result of find_if) was found. template struct is_found : std::integral_constant < bool, ! std::is_same::value > {}; // is_not_found // Returns true if a type T (the result of find_if) was not found. template struct is_not_found : std::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> { typedef std::tuple type; static type apply(std::pair const& p, T const& t) { return type(p.first, p.second, t); } 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)); } }; 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); } 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)); } }; template struct push_back, T> : push_back_st < std::make_index_sequence, std::tuple, T > {}; }}} // namespace boost::geometry::tuples #endif // BOOST_GEOMETRY_UTIL_TUPLES_HPP