Changeset d275344 in mainline
- Timestamp:
- 2018-07-05T21:41:23Z (7 years ago)
- 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)
- Location:
- uspace/lib/cpp/include/impl
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/cpp/include/impl/functional.hpp
r78a794ab rd275344 1104 1104 { 1105 1105 constexpr placeholder_t() = default; 1106 constexpr placeholder_t(const placeholder_t&) = default; 1107 constexpr placeholder_t(placeholder_t&&) = default; 1106 1108 }; 1107 1109 } … … 1121 1123 namespace aux 1122 1124 { 1123 template<size_t I>1124 struct bind_arg_index1125 { /* DUMMY BODY */ };1126 1127 template<class... Args>1128 class bind_bound_args1129 {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 1146 1125 template<class F, class... Args> 1147 1126 class bind_t; 1148 1127 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 */ 1149 1134 template<class... Args> 1150 1135 class bind_arg_filter … … 1157 1142 template<class T> 1158 1143 constexpr decltype(auto) operator[](T&& t) 1159 { // Since placeholders are constexpr, this is a worse match for them.1144 { 1160 1145 return forward<T>(t); 1161 1146 } … … 1193 1178 // TODO: conditional typedefs 1194 1179 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)...} 1200 1184 { /* DUMMY BODY */ } 1201 1185 … … 1214 1198 private: 1215 1199 function<decay_t<F>> func_; 1216 bind_bound_args<Args...> bound_args_;1200 tuple<decay_t<Args>...> bound_args_; 1217 1201 1218 1202 template<size_t... Is, class... ActualArgs> … … 1221 1205 ) 1222 1206 { 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 */ 1223 1216 bind_arg_filter<ActualArgs...> filter{forward<ActualArgs>(args)...}; 1224 1217 1225 1218 return invoke( 1226 1219 func_, 1227 filter[ bound_args_[bind_arg_index<Is>()]]...1220 filter[get<Is>(bound_args_)]... 1228 1221 ); 1229 1222 } … … 1247 1240 1248 1241 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 } 1250 1247 1251 1248 namespace placeholders -
uspace/lib/cpp/include/impl/tuple.hpp
r78a794ab rd275344 202 202 { /* DUMMY BODY */ } 203 203 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))... 206 207 { /* DUMMY BODY */ } 207 208 // TODO: enable only if Us is convertible to Ts and they are not same209 /* template<class... Us> */210 /* constexpr explicit tuple_impl(Us&&... us) */211 /* : tuple_element_wrapper<Is, Ts>(forward<Us>(us))... */212 /* { /1* DUMMY BODY *1/ } */213 208 }; 214 209
Note:
See TracChangeset
for help on using the changeset viewer.