// Boost.Geometry // Copyright (c) 2020-2021, Oracle and/or its affiliates. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle // Licensed under the Boost Software License version 1.0. // http://www.boost.org/users/license.html #ifndef BOOST_GEOMETRY_UTIL_SEQUENCE_HPP #define BOOST_GEOMETRY_UTIL_SEQUENCE_HPP #include namespace boost { namespace geometry { namespace util { // An alternative would be to use std:tuple and std::pair // but it would add dependency. template struct type_sequence {}; // true if T is a sequence template struct is_sequence : std::false_type {}; template struct is_sequence> : std::true_type {}; template struct is_sequence> : std::true_type {}; // number of elements in a sequence template struct sequence_size {}; template struct sequence_size> : std::integral_constant {}; template struct sequence_size> : std::integral_constant {}; // element of a sequence template struct sequence_element {}; template struct sequence_element> { using type = typename sequence_element>::type; }; template struct sequence_element<0, type_sequence> { using type = T; }; template struct sequence_element> : std::integral_constant < T, sequence_element>::value > {}; template struct sequence_element<0, std::integer_sequence> : std::integral_constant {}; template struct pack_front { static_assert(sizeof...(Ts) > 0, "Parameter pack can not be empty."); }; template struct pack_front { typedef T type; }; template struct sequence_front : sequence_element<0, Sequence> { static_assert(sequence_size::value > 0, "Sequence can not be empty."); }; template struct sequence_back : sequence_element::value - 1, Sequence> { static_assert(sequence_size::value > 0, "Sequence can not be empty."); }; template struct sequence_empty : std::integral_constant < bool, sequence_size::value == 0 > {}; // Defines type member for the first type in sequence that satisfies UnaryPred. template < typename Sequence, template class UnaryPred > struct sequence_find_if {}; template < typename T, typename ...Ts, template class UnaryPred > struct sequence_find_if, UnaryPred> : std::conditional < UnaryPred::value, T, // TODO: prevent instantiation for the rest of the sequence if value is true typename sequence_find_if, UnaryPred>::type > {}; template