Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Stream stream;
- stream
- .map ([] (int x) { return 10*x; }) // error
- .forEach ([] (int x) { cout << x << " ";});
- template argument deduction/substitution failed:
- βmain(int, char**)::<lambda(int)>β is not derived from βstd::function<Re(int)>β
- .map ([] (int x) { return 10*x; })
- requires a type parameter for `map`
- .map<int> ([] (int x) { return 10*x; })
- #include <iostream>
- #include <functional>
- using namespace std;
- template <typename Tfrom, typename Tto> class MappedStream;
- template <typename T>
- class Stream
- {
- public:
- void forEach(function< void(T) > action)
- {}
- template <typename Re>
- MappedStream<T,Re> map (function < Re(T)> mapping) {
- return MappedStream<T,Re>(*this, mapping);
- }
- };
- template <typename Tfrom, typename Tto>
- class MappedStream
- : public Stream<Tto>
- {
- public:
- MappedStream(Stream<Tfrom> & source,
- function <Tto(Tfrom)> mapping)
- {}
- };
- int main(int argc, char **argv)
- {
- Stream<int> stream;
- stream
- .map<int> ([] (int x) { return 10*x; })
- // XXXXX <- how to get rid of this?
- .forEach ([] (int x) { cout << x << " ";});
- return 0;
- }
- template <typename F, typename Re = std::result_of_t<F&(T)>>
- MappedStream<T,Re> map (F mapping) {
- return MappedStream<T,Re>(*this, mapping);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement