Advertisement
Guest User

Untitled

a guest
Aug 28th, 2015
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. Stream stream;
  2. stream
  3. .map ([] (int x) { return 10*x; }) // error
  4. .forEach ([] (int x) { cout << x << " ";});
  5.  
  6. template argument deduction/substitution failed:
  7. β€˜main(int, char**)::<lambda(int)>’ is not derived from β€˜std::function<Re(int)>’
  8. .map ([] (int x) { return 10*x; })
  9. requires a type parameter for `map`
  10.  
  11. .map<int> ([] (int x) { return 10*x; })
  12.  
  13. #include <iostream>
  14. #include <functional>
  15.  
  16. using namespace std;
  17.  
  18. template <typename Tfrom, typename Tto> class MappedStream;
  19.  
  20. template <typename T>
  21. class Stream
  22. {
  23. public:
  24. void forEach(function< void(T) > action)
  25. {}
  26.  
  27. template <typename Re>
  28. MappedStream<T,Re> map (function < Re(T)> mapping) {
  29. return MappedStream<T,Re>(*this, mapping);
  30. }
  31. };
  32.  
  33. template <typename Tfrom, typename Tto>
  34. class MappedStream
  35. : public Stream<Tto>
  36. {
  37. public:
  38. MappedStream(Stream<Tfrom> & source,
  39. function <Tto(Tfrom)> mapping)
  40. {}
  41. };
  42.  
  43. int main(int argc, char **argv)
  44. {
  45. Stream<int> stream;
  46. stream
  47. .map<int> ([] (int x) { return 10*x; })
  48. // XXXXX <- how to get rid of this?
  49. .forEach ([] (int x) { cout << x << " ";});
  50.  
  51. return 0;
  52. }
  53.  
  54. template <typename F, typename Re = std::result_of_t<F&(T)>>
  55. MappedStream<T,Re> map (F mapping) {
  56. return MappedStream<T,Re>(*this, mapping);
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement