Changeset daef596 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:
c866a83
Parents:
e9f2f4e
git-author:
Dzejrou <dzejrou@…> (2018-05-04 21:03:48)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:23)
Message:

cpp: added a variation of the aux::bind_t template that typedefs the result_type member type using a trick with extra boolean template parameter

File:
1 edited

Legend:

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

    re9f2f4e rdaef596  
    11231123    namespace aux
    11241124    {
    1125         template<class F, class... Args>
     1125        /**
     1126         * Note: Our internal bind return type has an extra type
     1127         *       template parameter and an extra bool template parameter.
     1128         *       We use this for the special version of bind that has
     1129         *       the return type to have a result_type typedef
     1130         *       (i.e. when the bool is true, the extra type parameter
     1131         *       is typedefed as result_type - see the structure below).
     1132         *       This is just a simplification of the implementation
     1133         *       so that we don't need to have two return types for
     1134         *       the two bind functions, because unlike function or
     1135         *       mem_fn, we know exactly when to make the typedef.
     1136         */
     1137
     1138        template<class, bool = false>
     1139        struct bind_conditional_result_type
     1140        { /* DUMMY BODY */ };
     1141
     1142        template<class R>
     1143        struct bind_conditional_result_type<R, true>
     1144        {
     1145            using result_type = R;
     1146        };
     1147
     1148        template<class, bool, class, class...>
    11261149        class bind_t;
    11271150
     
    11621185                }
    11631186
    1164                 template<class F, class... BindArgs>
    1165                 constexpr decltype(auto) operator[](const bind_t<F, BindArgs...> b)
     1187                template<class R, bool B, class F, class... BindArgs>
     1188                constexpr decltype(auto) operator[](const bind_t<R, B, F, BindArgs...> b)
    11661189                {
    11671190                    return b; // TODO: bind subexpressions
     
    11731196        };
    11741197
    1175         template<class F, class... Args>
    1176         class bind_t
    1177         {
    1178             // TODO: conditional typedefs
     1198        template<class R, bool HasResultType, class F, class... Args>
     1199        class bind_t: public bind_conditional_result_type<R, HasResultType>
     1200        {
    11791201            public:
    11801202                template<class G, class... BoundArgs>
     
    12281250    { /* DUMMY BODY */ };
    12291251
    1230     template<class F, class... Args>
    1231     struct is_bind_expression<aux::bind_t<F, Args...>>
     1252    template<class R, bool B, class F, class... Args>
     1253    struct is_bind_expression<aux::bind_t<R, B, F, Args...>>
    12321254        : true_type
    12331255    { /* DUMMY BODY */ };
    12341256
    12351257    template<class F, class... Args>
    1236     aux::bind_t<F, Args...> bind(F&& f, Args&&... args)
    1237     {
    1238         return aux::bind_t<F, Args...>{forward<F>(f), forward<Args>(args)...};
     1258    aux::bind_t<void, false, F, Args...> bind(F&& f, Args&&... args)
     1259    {
     1260        return aux::bind_t<void, false, F, Args...>{forward<F>(f), forward<Args>(args)...};
    12391261    }
    12401262
    12411263    template<class R, class F, class... Args>
    1242     aux::bind_t<F, Args...> bind(F&& f, Args&&... args)
    1243     {
    1244         // TODO: this one should have a result_type typedef equal to R
    1245         return aux::bind_t<F, Args...>{forward<F>(f), forward<Args>(args)...};
     1264    aux::bind_t<R, true, F, Args...> bind(F&& f, Args&&... args)
     1265    {
     1266        return aux::bind_t<R, true, F, Args...>{forward<F>(f), forward<Args>(args)...};
    12461267    }
    12471268
Note: See TracChangeset for help on using the changeset viewer.