Changeset aa0fa86a in mainline


Ignore:
Timestamp:
2018-07-05T21:41:22Z (6 years ago)
Author:
Dzejrou <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
93af98f
Parents:
255bb63
git-author:
Dzejrou <dzejrou@…> (2018-05-01 21:57:00)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:22)
Message:

cpp: added pair::pair(piecewise_construct_t, …), but had to temporarily remove templated tuple constructor which needs is_convertible etc on variadic types

Location:
uspace/lib/cpp/include/impl
Files:
2 edited

Legend:

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

    r255bb63 raa0fa86a  
    207207
    208208                // TODO: enable only if Us is convertible to Ts and they are not same
    209                 template<class... Us>
    210                 constexpr explicit tuple_impl(Us&&... us)
    211                     : tuple_element_wrapper<Is, Ts>(forward<Us>(us))...
    212                 { /* DUMMY BODY */ }
     209                /* template<class... Us> */
     210                /* constexpr explicit tuple_impl(Us&&... us) */
     211                /*     : tuple_element_wrapper<Is, Ts>(forward<Us>(us))... */
     212                /* { /1* DUMMY BODY *1/ } */
    213213        };
    214214
  • uspace/lib/cpp/include/impl/utility.hpp

    r255bb63 raa0fa86a  
    135135
    136136    /**
     137     * 20.5.2, class template integer_sequence:
     138     */
     139
     140    template<class T, T... Is>
     141    struct integer_sequence
     142    {
     143        using value_type = T;
     144
     145        static constexpr size_t size() noexcept
     146        {
     147            return sizeof...(Is);
     148        }
     149
     150        using next = integer_sequence<T, Is..., sizeof...(Is)>;
     151    };
     152
     153    template<std::size_t... Is>
     154    using index_sequence = integer_sequence<std::size_t, Is...>;
     155
     156    /**
     157     * 20.5.3, alias template make_integer_sequence:
     158     */
     159
     160    namespace aux
     161    {
     162        template<class T, uintmax_t N>
     163        struct make_integer_sequence
     164        {
     165            /**
     166             * Recursive to the bottom case below, appends sizeof...(Is) in
     167             * every next "call", building the sequence.
     168             */
     169            using type = typename make_integer_sequence<T, N - 1>::type::next;
     170        };
     171
     172        template<class T>
     173        struct make_integer_sequence<T, std::uintmax_t(0)>
     174        {
     175            using type = integer_sequence<T>;
     176        };
     177    }
     178
     179
     180    /**
     181     * Problem: We can't specialize the N parameter because it is a value parameter
     182     *          depending on a type parameter.
     183     * Solution: According to the standard: if N is negative, the program is ill-formed,
     184     *           so we just recast it to uintmax_t :)
     185     */
     186    template<class T, T N>
     187    using make_integer_sequence = typename aux::make_integer_sequence<T, std::uintmax_t(N)>::type;
     188
     189    template<size_t N>
     190    using make_index_sequence = make_integer_sequence<std::size_t, N>;
     191
     192    /**
    137193     * 20.3, pairs:
    138194     */
     195
     196    template<size_t, class>
     197    class tuple_element;
     198
     199    template<size_t I, class T>
     200    using tuple_element_t = typename tuple_element<I, T>::type;
     201
     202    template<class...>
     203    class tuple;
     204
     205    template<size_t I, class... Ts>
     206    constexpr tuple_element_t<I, tuple<Ts...>>&& get(tuple<Ts...>&&) noexcept;
     207
     208    namespace aux
     209    {
     210        template<class T, class... Args, size_t... Is>
     211        T from_tuple(tuple<Args...>&& tpl, index_sequence<Is...>)
     212        {
     213            return T{get<Is>(move(tpl))...};
     214        }
     215
     216        template<class T, class... Args>
     217        T from_tuple(tuple<Args...>&& tpl)
     218        {
     219            return from_tuple<T>(move(tpl), make_index_sequence<sizeof...(Args)>{});
     220        }
     221    }
    139222
    140223    struct piecewise_construct_t
     
    142225        explicit piecewise_construct_t() = default;
    143226    };
     227
     228    inline constexpr piecewise_construct_t piecewise_construct{};
    144229
    145230    template<typename T1, typename T2>
     
    179264        { /* DUMMY BODY */ }
    180265
    181         /* TODO: need tuple, piecewise_construct_t
    182266        template<class... Args1, class... Args2>
    183267        pair(piecewise_construct_t, tuple<Args1...> first_args, tuple<Args2...> second_args)
    184         {
    185             // TODO:
    186         }
    187         */
     268            : first{aux::from_tuple<first_type>(move(first_args))},
     269              second{aux::from_tuple<second_type>(move(second_args))}
     270        { /* DUMMY BODY */ }
    188271
    189272        pair& operator=(const pair& other)
     
    383466        return get<1>(move(p));
    384467    }
    385 
    386     /**
    387      * 20.5.2, class template integer_sequence:
    388      */
    389 
    390     template<class T, T... Is>
    391     struct integer_sequence
    392     {
    393         using value_type = T;
    394 
    395         static constexpr size_t size() noexcept
    396         {
    397             return sizeof...(Is);
    398         }
    399 
    400         using next = integer_sequence<T, Is..., sizeof...(Is)>;
    401     };
    402 
    403     template<std::size_t... Is>
    404     using index_sequence = integer_sequence<std::size_t, Is...>;
    405 
    406     /**
    407      * 20.5.3, alias template make_integer_sequence:
    408      */
    409 
    410     namespace aux
    411     {
    412         template<class T, uintmax_t N>
    413         struct make_integer_sequence
    414         {
    415             /**
    416              * Recursive to the bottom case below, appends sizeof...(Is) in
    417              * every next "call", building the sequence.
    418              */
    419             using type = typename make_integer_sequence<T, N - 1>::type::next;
    420         };
    421 
    422         template<class T>
    423         struct make_integer_sequence<T, std::uintmax_t(0)>
    424         {
    425             using type = integer_sequence<T>;
    426         };
    427     }
    428 
    429 
    430     /**
    431      * Problem: We can't specialize the N parameter because it is a value parameter
    432      *          depending on a type parameter.
    433      * Solution: According to the standard: if N is negative, the program is ill-formed,
    434      *           so we just recast it to uintmax_t :)
    435      */
    436     template<class T, T N>
    437     using make_integer_sequence = typename aux::make_integer_sequence<T, std::uintmax_t(N)>::type;
    438 
    439     template<size_t N>
    440     using make_index_sequence = make_integer_sequence<std::size_t, N>;
    441468}
    442469
Note: See TracChangeset for help on using the changeset viewer.