Changeset d275344 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:
e9f2f4e
Parents:
78a794ab
git-author:
Dzejrou <dzejrou@…> (2018-05-04 20:40:34)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:23)
Message:

cpp: fixed passing references to bind without std::ref or std::cref, now they are not modified and the user needs to use the aforementioned functions

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

Legend:

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

    r78a794ab rd275344  
    11041104        {
    11051105            constexpr placeholder_t() = default;
     1106            constexpr placeholder_t(const placeholder_t&) = default;
     1107            constexpr placeholder_t(placeholder_t&&) = default;
    11061108        };
    11071109    }
     
    11211123    namespace aux
    11221124    {
    1123         template<size_t I>
    1124         struct bind_arg_index
    1125         { /* DUMMY BODY */ };
    1126 
    1127         template<class... Args>
    1128         class bind_bound_args
    1129         {
    1130             public:
    1131                 template<class... BoundArgs>
    1132                 constexpr bind_bound_args(BoundArgs&&... args)
    1133                     : tpl_{forward<BoundArgs>(args)...}
    1134                 { /* DUMMY BODY */ }
    1135 
    1136                 template<size_t I>
    1137                 constexpr decltype(auto) operator[](bind_arg_index<I>)
    1138                 {
    1139                     return get<I>(tpl_);
    1140                 }
    1141 
    1142             private:
    1143                 tuple<Args...> tpl_;
    1144         };
    1145 
    11461125        template<class F, class... Args>
    11471126        class bind_t;
    11481127
     1128        /**
     1129         * Filter class that uses its overloaded operator[]
     1130         * to filter our placeholders, reference_wrappers and bind
     1131         * subexpressions and replace them with the correct
     1132         * arguments (extracts references, calls the subexpressions etc).
     1133         */
    11491134        template<class... Args>
    11501135        class bind_arg_filter
     
    11571142                template<class T>
    11581143                constexpr decltype(auto) operator[](T&& t)
    1159                 { // Since placeholders are constexpr, this is a worse match for them.
     1144                {
    11601145                    return forward<T>(t);
    11611146                }
     
    11931178            // TODO: conditional typedefs
    11941179            public:
    1195                 // TODO: T& gets captured by ref, should be by value :/
    1196                 template<class... BoundArgs>
    1197                 constexpr bind_t(F&& f, BoundArgs&&... args)
    1198                     : func_{forward<F>(f)},
    1199                       bound_args_{forward<BoundArgs>(args)...}
     1180                template<class G, class... BoundArgs>
     1181                constexpr bind_t(G&& g, BoundArgs&&... args)
     1182                    : func_{forward<F>(g)},
     1183                      bound_args_{forward<Args>(args)...}
    12001184                { /* DUMMY BODY */ }
    12011185
     
    12141198            private:
    12151199                function<decay_t<F>> func_;
    1216                 bind_bound_args<Args...> bound_args_;
     1200                tuple<decay_t<Args>...> bound_args_;
    12171201
    12181202                template<size_t... Is, class... ActualArgs>
     
    12211205                )
    12221206                {
     1207                    /**
     1208                     * The expression filter[bound_args_[bind_arg_index<Is>()]]...
     1209                     * here expands bind_arg_index to 0, 1, ... sizeof...(ActualArgs) - 1
     1210                     * and then passes this variadic list of indices to the bound_args_
     1211                     * tuple which extracts the bound args from it.
     1212                     * Our filter will then have its operator[] called on each of them
     1213                     * and filter out the placeholders, reference_wrappers etc and changes
     1214                     * them to the actual arguments.
     1215                     */
    12231216                    bind_arg_filter<ActualArgs...> filter{forward<ActualArgs>(args)...};
    12241217
    12251218                    return invoke(
    12261219                        func_,
    1227                         filter[bound_args_[bind_arg_index<Is>()]]...
     1220                        filter[get<Is>(bound_args_)]...
    12281221                    );
    12291222                }
     
    12471240
    12481241    template<class R, class F, class... Args>
    1249     aux::bind_t<F, Args...> bind(F&& f, Args&&... 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)...};
     1246    }
    12501247
    12511248    namespace placeholders
  • uspace/lib/cpp/include/impl/tuple.hpp

    r78a794ab rd275344  
    202202                { /* DUMMY BODY */ }
    203203
    204                 constexpr explicit tuple_impl(Ts&&... ts)
    205                     : tuple_element_wrapper<Is, Ts>(forward<Ts>(ts))...
     204                template<class... Us>
     205                constexpr explicit tuple_impl(Us&&... us)
     206                    : tuple_element_wrapper<Is, Ts>(forward<Us>(us))...
    206207                { /* DUMMY BODY */ }
    207 
    208                 // 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                 /* { /1* DUMMY BODY *1/ } */
    213208        };
    214209
Note: See TracChangeset for help on using the changeset viewer.