From 8ef765851871f5fed7ffdc2a192291175c400794 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sat, 18 Jan 2020 18:44:43 +0200 Subject: [PATCH] Implement mp_rotate_right in terms of mp_rotate_left --- include/boost/mp11/algorithm.hpp | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index 4ec9aea..c04143e 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -1105,22 +1105,13 @@ using mp_starts_with = typename detail::mp_starts_with_impl::type; namespace detail { -template struct canonical_rotation -{ - // provide a default rotation so that "no type named 'type'" errors appear in mp_rotate_impl instead of here - using type = mp_size_t<0>; -}; +// limit divisor to 1 to avoid division by 0 and give a rotation of 0 for lists containing 0 or 1 elements +template using canonical_left_rotation = mp_size_t; -template class L, class... T, std::size_t N> struct canonical_rotation, N> -{ - // limit divisor to 1 to avoid division by 0 and give a rotation of 0 for lists containing 0 or 1 elements - using type = mp_size_t; -}; - -template using canonical_rotation_t = typename canonical_rotation::type; +// perform right rotation as a left rotation by inverting the number of elements to rotate +template using canonical_right_rotation = mp_size_t; struct left_rotation; -struct right_rotation; template struct mp_rotate_impl { @@ -1139,19 +1130,13 @@ template class L, class... T, std::size_t N> struct mp_rotate using type = mp_rename, N>, mp_take_c, N>>, L>; }; -template class L, class... T, std::size_t N> struct mp_rotate_impl, mp_size_t, right_rotation> -{ - // perform right rotation as a left rotation by inverting the number of elements to rotate - using type = typename mp_rotate_impl, canonical_rotation_t, sizeof...(T) - N>, left_rotation>::type; -}; - } // namespace detail -template using mp_rotate_left_c = typename detail::mp_rotate_impl, detail::left_rotation>::type; +template using mp_rotate_left_c = typename detail::mp_rotate_impl::value, N>, detail::left_rotation>::type; template using mp_rotate_left = mp_rotate_left_c; // mp_rotate_right(_c) -template using mp_rotate_right_c = typename detail::mp_rotate_impl, detail::right_rotation>::type; +template using mp_rotate_right_c = mp_rotate_left::value, N>>; template using mp_rotate_right = mp_rotate_right_c; // mp_min_element