Changeset 9c9ee5d in mainline


Ignore:
Timestamp:
2018-07-05T21:41:23Z (6 years ago)
Author:
Dzejrou <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6175b78
Parents:
f6f636f
git-author:
Dzejrou <dzejrou@…> (2018-05-12 21:01:13)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:23)
Message:

cpp: fixed bugs found by the tuple tests

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

Legend:

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

    rf6f636f r9c9ee5d  
    8181    template<class... Tuples>
    8282    constexpr aux::tuple_cat_type_t<Tuples...> tuple_cat(Tuples&&... tpls)
    83     {
     83    { // TODO: currently does not work because of index mismatch
    8484        return aux::tuple_cat(
    8585            forward<Tuples>(tpls)...,
     
    206206                    : tuple_element_wrapper<Is, Ts>(forward<Us>(us))...
    207207                { /* DUMMY BODY */ }
     208
     209                template<class... Us>
     210                constexpr tuple_impl(const tuple<Us...>& tpl)
     211                    : tuple_impl{tpl, make_index_sequence<sizeof...(Us)>{}}
     212                { /* DUMMY BODY */ }
     213
     214                template<class... Us>
     215                constexpr tuple_impl(tuple<Us...>&& tpl)
     216                    : tuple_impl{move<tuple<Us...>>(tpl), make_index_sequence<sizeof...(Us)>{}}
     217                { /* DUMMY BODY */ }
     218
     219                template<class... Us, size_t... Iss>
     220                constexpr tuple_impl(const tuple<Us...>& tpl, index_sequence<Iss...>)
     221                    : tuple_impl{get<Iss>(tpl)...}
     222                { /* DUMMY BODY */ }
     223
     224                template<class... Us, size_t... Iss>
     225                constexpr tuple_impl(tuple<Us...>&& tpl, index_sequence<Iss...>)
     226                    : tuple_impl{get<Iss>(move(tpl))...}
     227                { /* DUMMY BODY */ }
    208228        };
    209229
     
    313333            { /* DUMMY BODY */ }
    314334
    315             template<class... Us>
    316             constexpr explicit tuple(Us&&... us)
     335            template<class... Us> // TODO: is_convertible == true for all Us to all Ts
     336            constexpr explicit tuple(Us&&... us, enable_if_t<sizeof...(Us) == sizeof...(Ts)>* = nullptr)
    317337                : base_t(forward<Us>(us)...)
    318338            { /* DUMMY BODY */ }
     
    322342
    323343            template<class... Us>
    324             constexpr tuple(const tuple<Us...>& tpl)
     344            constexpr tuple(const tuple<Us...>& tpl, enable_if_t<sizeof...(Us) == sizeof...(Ts)>* = nullptr)
    325345                : base_t(tpl)
    326346            { /* DUMMY BODY */ }
    327347
    328348            template<class... Us>
    329             constexpr tuple(tuple<Us...>&& tpl)
    330                 : base_t(forward<tuple<Us>>(tpl)...)
     349            constexpr tuple(tuple<Us...>&& tpl, enable_if_t<sizeof...(Us) == sizeof...(Ts)>* = nullptr)
     350                : base_t(move(tpl))
    331351            { /* DUMMY BODY */ }
    332352
     
    356376            tuple& operator=(const tuple& other)
    357377            {
    358                 aux::tuple_ops<0, sizeof...(Ts) - 1>::assign(*this, other);
     378                aux::tuple_ops<0, sizeof...(Ts) - 1>::assign_copy(*this, other);
    359379
    360380                return *this;
     
    363383            tuple& operator=(tuple&& other) noexcept(aux::tuple_noexcept_assignment<Ts...>::value)
    364384            {
    365                 aux::tuple_ops<0, sizeof...(Ts) - 1>::assign(*this, forward<tuple>(other));
     385                aux::tuple_ops<0, sizeof...(Ts) - 1>::assign_move(*this, move(other));
    366386
    367387                return *this;
     
    371391            tuple& operator=(const tuple<Us...>& other)
    372392            {
    373                 aux::tuple_ops<0, sizeof...(Ts) - 1>::assign(*this, other);
     393                aux::tuple_ops<0, sizeof...(Ts) - 1>::assign_copy(*this, other);
    374394
    375395                return *this;
     
    379399            tuple& operator=(tuple<Us...>&& other)
    380400            {
    381                 aux::tuple_ops<0, sizeof...(Ts) - 1>::assign(*this, forward<Us>(other)...);
     401                aux::tuple_ops<0, sizeof...(Ts) - 1>::assign_move(*this, move(other));
    382402
    383403                return *this;
     
    389409                get<0>(*this) = p.first;
    390410                get<1>(*this) = p.second;
     411
     412                return *this;
    391413            }
    392414
     
    396418                get<0>(*this) = forward<U1>(p.first);
    397419                get<1>(*this) = forward<U2>(p.second);
     420
     421                return *this;
    398422            }
    399423
  • uspace/lib/cpp/include/internal/tuple/tuple_ops.hpp

    rf6f636f r9c9ee5d  
    5050    {
    5151        template<class T, class U>
    52         static void assign(T&& lhs, U&& rhs)
     52        static void assign_copy(T& lhs, const U& rhs)
    5353        {
    54             get<I>(forward<T>(lhs)) = get<I>(forward<U>(rhs));
     54            get<I>(lhs) = get<I>(rhs);
    5555
    56             tuple_ops<I + 1, N>::assign(forward<T>(lhs), forward<U>(rhs));
     56            tuple_ops<I + 1, N>::assign_copy(lhs, rhs);
     57        }
     58
     59        template<class T, class U>
     60        static void assign_move(T& lhs, U&& rhs)
     61        {
     62            get<I>(lhs) = move(get<I>(rhs));
     63
     64            tuple_ops<I + 1, N>::assign_move(lhs, move(rhs));
    5765        }
    5866
     
    8391    {
    8492        template<class T, class U>
    85         static void assign(T&& lhs, U&& rhs)
     93        static void assign_copy(T& lhs, const U& rhs)
    8694        {
    87             get<N>(forward<T>(lhs)) = get<N>(forward<U>(rhs));
     95            get<N>(lhs) = get<N>(rhs);
     96        }
     97
     98        template<class T, class U>
     99        static void assign_move(T& lhs, U&& rhs)
     100        {
     101            get<N>(lhs) = move(get<N>(rhs));
    88102        }
    89103
Note: See TracChangeset for help on using the changeset viewer.