Changeset 3d6f7f3 in mainline


Ignore:
Timestamp:
2018-07-05T21:41:21Z (6 years ago)
Author:
Dzejrou <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4a7e47b
Parents:
921174c
git-author:
Dzejrou <dzejrou@…> (2018-04-22 15:47:11)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:21)
Message:

cpp: reorganized tuple header, added a WIP version of tuple_cat (mismatched indices at the moment)

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

Legend:

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

    r921174c r3d6f7f3  
    3131
    3232#include <internal/aux.hpp>
     33#include <internal/tuple_cat.hpp>
     34#include <internal/tuple_ops.hpp>
    3335#include <functional>
    3436#include <type_traits>
     
    9395    }
    9496
    95     template<class... Tuples> // TODO: dafuq is ctypes?
    96     constexpr tuple<Tuples...> tuple_cat(Tuples&&... tpls);
     97    template<class... Tuples>
     98    constexpr aux::tuple_cat_type_t<Tuples...> tuple_cat(Tuples&&... tpls)
     99    {
     100        return aux::tuple_cat(
     101            forward<Tuples>(tpls)...,
     102            make_index_sequence<sizeof...(Tuples)>{},
     103            aux::generate_indices_t<Tuples...>{}
     104        );
     105    }
    97106
    98107    /**
     
    180189            constexpr tuple_element_wrapper() = default;
    181190
    182             constexpr explicit tuple_element_wrapper(T val)
    183                 : value{val}
     191            constexpr explicit tuple_element_wrapper(T&& val)
     192                : value{forward<T>(val)}
     193            { /* DUMMY BODY */ }
     194
     195            template<
     196                class U,
     197                class = enable_if_t<
     198                    is_convertible_v<U, T> && !is_same_v<U, T>,
     199                    void
     200                >
     201            >
     202            constexpr explicit tuple_element_wrapper(U&& val)
     203                : value(forward<U>(val))
    184204            { /* DUMMY BODY */ }
    185205
     
    198218                { /* DUMMY BODY */ }
    199219
    200                 constexpr explicit tuple_impl(const Ts&... ts)
    201                     : tuple_element_wrapper<Is, Ts>(ts)...
     220                constexpr explicit tuple_impl(Ts&&... ts)
     221                    : tuple_element_wrapper<Is, Ts>(forward<Ts>(ts))...
     222                { /* DUMMY BODY */ }
     223
     224                // TODO: enable only if Us is convertible to Ts and they are not same
     225                template<class... Us>
     226                constexpr explicit tuple_impl(Us&&... us)
     227                    : tuple_element_wrapper<Is, Ts>(forward<Us>(us))...
    202228                { /* DUMMY BODY */ }
    203229        };
     
    255281        return wrapper.value;
    256282    }
    257 
    258283
    259284    namespace aux
     
    286311    }
    287312
    288     namespace aux
    289     {
    290         template<size_t I, size_t N>
    291         struct tuple_ops
    292         {
    293             template<class T, class U>
    294             static void assign(T&& lhs, U&& rhs)
    295             {
    296                 get<I>(forward<T>(lhs)) = get<I>(forward<U>(rhs));
    297 
    298                 tuple_ops<I + 1, N>::assign(forward<T>(lhs), forward<U>(rhs));
    299             }
    300 
    301             template<class T, class U>
    302             static void swap(T& lhs, U& rhs)
    303             {
    304                 std::swap(get<I>(lhs), get<I>(rhs));
    305 
    306                 tuple_ops<I + 1, N>::swap(lhs, rhs);
    307             }
    308 
    309             template<class T, class U>
    310             static bool eq(const T& lhs, const U& rhs)
    311             {
    312                 return (get<I>(lhs) == get<I>(rhs)) && tuple_ops<I + 1, N>::eq(lhs, rhs);
    313             }
    314 
    315             template<class T, class U>
    316             static bool lt(const T& lhs, const U& rhs)
    317             {
    318                 return (get<I>(lhs) < get<I>(rhs)) ||
    319                     (!(get<I>(rhs) < get<I>(lhs)) && tuple_ops<I + 1, N>::lt(lhs, rhs));
    320             }
    321         };
    322 
    323         template<size_t N>
    324         struct tuple_ops<N, N>
    325         {
    326             template<class T, class U>
    327             static void assign(T&& lhs, U&& rhs)
    328             {
    329                 get<N>(forward<T>(lhs)) = get<N>(forward<U>(rhs));
    330             }
    331 
    332             template<class T, class U>
    333             static void swap(T& lhs, U& rhs)
    334             {
    335                 std::swap(get<N>(lhs), get<N>(rhs));
    336             }
    337 
    338             template<class T, class U>
    339             static bool eq(const T& lhs, const U& rhs)
    340             {
    341                 return get<N>(lhs) == get<N>(rhs);
    342             }
    343 
    344             template<class T, class U>
    345             static bool lt(const T& lhs, const U& rhs)
    346             {
    347                 return get<N>(lhs) < get<N>(rhs);
    348             }
    349         };
    350     }
    351 
    352313    /**
    353314     * 20.4.2, class template tuple:
    354315     */
    355 
    356316
    357317    template<class... Ts>
     
    382342            tuple(tuple&&) = default;
    383343
    384             /* template<class... Us> */
    385             /* constexpr tuple(const tuple<Us...>& tpl) */
    386             /*     : base_t(tpl) */
    387             //{ /* DUMMY BODY */ }
    388 
    389             /* template<class... Us> */
    390             /* constexpr tuple(tuple<Us...>& tpl) */
    391             /*     : base_t(forward<tuple<Us>>(tpl)...) */
    392             //{ /* DUMMY BODY */ }
     344            template<class... Us>
     345            constexpr tuple(const tuple<Us...>& tpl)
     346                : base_t(tpl)
     347            { /* DUMMY BODY */ }
     348
     349            template<class... Us>
     350            constexpr tuple(tuple<Us...>&& tpl)
     351                : base_t(forward<tuple<Us>>(tpl)...)
     352            { /* DUMMY BODY */ }
    393353
    394354            // TODO: pair related construction and assignment needs convertibility, not size
Note: See TracChangeset for help on using the changeset viewer.