title: C++ Function signature that returns a PPL task?
body: <p>I am a total noob when it comes to using PPL tasks within the C++ environment, so I am having a hard time to figure out what would be the C++ syntax of the following C# code:</p>
  
  <pre><code>private static async Task&lt;RandomAccessStreamReference&gt; GetImageStreamRef()
  {
      return RandomAccessStreamReference.CreateFromStream(await GetImageStream());
  }
  
  private static async Task&lt;IRandomAccessStream&gt; GetImageStream()
  {
      var stream = new InMemoryRandomAccessStream();
      var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.BmpEncoderId, stream);
      encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, width, height, 96, 96, imageBytes);
      await encoder.FlushAsync();
      return stream;
  }
  </code></pre>
  
  <p>This C# code was taken from the <a href="http://msdn.microsoft.com/en-us/library/windows/apps/jj712230.aspx" rel="nofollow">Windows Store reversi Microsoft sample code</a>. The best I could get so far is this:</p>
  
  <pre><code>Concurrency::task&lt;IRandomAccessStream^&gt; GetImageStream()
  {
      auto stream = ref new InMemoryRandomAccessStream();
      task&lt;BitmapEncoder^&gt;(BitmapEncoder::CreateAsync(BitmapEncoder::JpegEncoderId, Stream)).then([this, stream, width, height, imageBytes](BitmapEncoder^ encoder)
      {
          encoder-&gt;SetPixelData(BitmapPixelFormat::Rgba8, BitmapAlphaMode::Ignore, width, height, 96.0, 96.0, imageBytes);
          return encoder-&gt;FlushAsync();
      }).then([this, stream]()
      {
          return stream; //Does this even make sense?
      });
      //return stream; //Not sure if I should have this here?
  }
  </code></pre>
  
  <p>But it generates the following compile error:</p>
  
  <pre><code>error C4716: 'GetImageStream' : must return a value
  </code></pre>
  
  <p>I understand why this error happens, but I have no clue how I can have a function that returns a task without having a return value at two different locations? I haven't even tackled GetImageStream yet.</p>
  
  <p>I am not even sure I took the right path into this...</p>
  
  <p>Thank you!</p>