Changeset 82ef902 in mainline


Ignore:
Timestamp:
2018-07-05T21:41:20Z (6 years ago)
Author:
Dzejrou <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
dbaf221
Parents:
229dff7b
git-author:
Dzejrou <dzejrou@…> (2018-03-11 14:15:49)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:20)
Message:

cpp: added integer sequences

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/cpp/include/impl/utility.hpp

    r229dff7b r82ef902  
    209209        }
    210210    };
     211
     212    /**
     213     * 20.5.2, class template integer_sequence:
     214     */
     215
     216    template<class T, T... Is>
     217    struct integer_sequence
     218    {
     219        using value_type = T;
     220
     221        static constexpr size_t size() noexcept
     222        {
     223            return sizeof...(Is);
     224        }
     225
     226        using next = integer_sequence<T, Is..., sizeof...(Is)>;
     227    };
     228
     229    template<std::size_t... Is>
     230    using index_sequence = integer_sequence<std::size_t, Is...>;
     231
     232    /**
     233     * 20.5.3, alias template make_integer_sequence:
     234     */
     235
     236    namespace aux
     237    {
     238        template<class T, std::uintmax_t N>
     239        struct make_integer_sequence
     240        {
     241            /**
     242             * Recursive to the bottom case below, appends sizeof...(Is) in
     243             * every next "call", building the sequence.
     244             */
     245            using type = typename make_integer_sequence<T, N - 1>::type::next;
     246        };
     247
     248        template<class T>
     249        struct make_integer_sequence<T, std::uintmax_t(0)>
     250        {
     251            using type = integer_sequence<T>;
     252        };
     253    }
     254
     255
     256    /**
     257     * Problem: We can't specialize the N parameter because it is a value parameter
     258     *          depending on a type parameter.
     259     * Solution: According to the standard: if N is negative, the program is ill-formed,
     260     *           so we just recast it to uintmax_t :)
     261     */
     262    template<class T, T N>
     263    using make_integer_sequence = typename aux::make_integer_sequence<T, std::uintmax_t(N)>::type;
     264
     265    template<size_t N>
     266    using make_index_sequence = make_integer_sequence<std::size_t, N>;
    211267}
    212268
Note: See TracChangeset for help on using the changeset viewer.