fork download
  1. #include <vector>
  2. #include <memory>
  3.  
  4. typedef std::vector<int> CBuffer;
  5.  
  6. static CBuffer& PostProcess(CBuffer& data) {
  7. for(auto& el : data)
  8. el /= 2;
  9. return data;
  10. }
  11.  
  12. struct CSource
  13. {
  14. CSource() : _data(std::make_shared<CBuffer>(10)) {}
  15.  
  16. std::shared_ptr<CBuffer> GetData() { return _data; }
  17. std::shared_ptr<const CBuffer> GetData() const { return _data; }
  18.  
  19. private:
  20. std::shared_ptr<CBuffer> _data;
  21. };
  22.  
  23. struct CPlug
  24. {
  25. CPlug(bool postProcess = true) : m_postProcess(postProcess) { }
  26.  
  27. std::shared_ptr<const CBuffer> ProcessData() const
  28. {
  29. /* get the data from the source, implicitely const */
  30. auto buffer = m_source.GetData();
  31.  
  32. if (!m_postProcess)
  33. return buffer;
  34.  
  35. // clone!
  36. auto clone = *buffer;
  37. return std::make_shared<CBuffer>(PostProcess(clone));
  38. }
  39.  
  40. private:
  41. bool m_postProcess;
  42. CSource m_source;
  43. };
  44.  
  45. int main()
  46. {
  47. CPlug intance;
  48. auto x = instance.ProcessData();
  49. }
  50.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:48:14: error: ‘instance’ was not declared in this scope
prog.cpp:48:35: error: unable to deduce ‘auto’ from ‘<expression error>’
prog.cpp:48:10: warning: unused variable ‘x’ [-Wunused-variable]
stdout
Standard output is empty