# \[solved\] FormatManager.createReaderFor and MemoryInputStream question

**URL:** <https://forum.juce.com/t/solved-formatmanager-createreaderfor-and-memoryinputstream-question/45394>\
**Category:** General JUCE discussion\
**Created:** [April 7, 2021, 1:31pm UTC](https://forum.juce.com/t/solved-formatmanager-createreaderfor-and-memoryinputstream-question/45394 "2021-04-07T13:31:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![KoenTanghe](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/koentanghe/32/533_2.png) [@KoenTanghe](https://forum.juce.com/u/KoenTanghe)\
**Post date:** [April 7, 2021, 1:31pm UTC](https://forum.juce.com/t/solved-formatmanager-createreaderfor-and-memoryinputstream-question/45394/1 "2021-04-07T13:31:37Z")

</div>

Hi,

I recently updated a plugin to build with VS2019 and a later version of JUCE (“final JUCE 5 commit”), and had to go through a few fixes related to ScopedPointer being phased out.  
All fairly simple to fix, but there was another case where I didn’t find right away how to solve it, and for which I could use some feedback here:

This is the old code, that used to compile in VS2015 and a slightly older version of JUCE:

```
MemoryInputStream* stream = new MemoryInputStream(fileData, true);
AudioFormatReader* reader = m_FormatManager.createReaderFor(stream);

```

but in VS2019 and with the newer JUCE version now gives compilation error:

```
Error	C2664	'juce::AudioFormatReader *juce::AudioFormatManager::createReaderFor(const juce::File &)': cannot convert argument 1 from 'juce::MemoryInputStream *' to 'const juce::File &'

```

As the newer JUCE method signature uses `std::unique_ptr`, I then tried this (note that the createReaderFor method takes a `std::unique_ptr<InputStream>` and not a `std::unique_ptr<MemoryInputStream>`):

```
std::unique_ptr<InputStream> stream = std::make_unique<MemoryInputStream>(fileData, true);
AudioFormatReader* reader = m_FormatManager.createReaderFor(stream);

```

but that gave compilation error:

```
Error	C2280	'std::unique_ptr<ObjectType,std::default_delete<ObjectType>>::unique_ptr(const std::unique_ptr<ObjectType,std::default_delete<ObjectType>> &)': attempting to reference a deleted function

```

The way I got it to work was using a `std::move`, like so:

```
std::unique_ptr<InputStream> stream = std::make_unique<MemoryInputStream>(fileData, true);
AudioFormatReader* reader = m_FormatManager.createReaderFor(std::move(stream));

```

Is it normal that I need that explicit `std::move` here?

---

<div class="post-metadata">

**Author:** ![xenakios](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/xenakios/32/4047_2.png) [@xenakios](https://forum.juce.com/u/xenakios)\
**Post date:** [April 7, 2021, 1:42pm UTC](https://forum.juce.com/t/solved-formatmanager-createreaderfor-and-memoryinputstream-question/45394/2 "2021-04-07T13:42:28Z")

</div>

> [@KoenTanghe](#):
>
> Is it normal that I need that explicit `std::move` here?

Yes, as the documentation for createReaderFor says :

> [@](#):
>
> The stream object that is passed-in will be deleted by this method or by the reader that is returned, so the caller should not keep any references to it.

---

<div class="post-metadata">

**Author:** ![KoenTanghe](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/koentanghe/32/533_2.png) [@KoenTanghe](https://forum.juce.com/u/KoenTanghe)\
**Post date:** [April 7, 2021, 3:18pm UTC](https://forum.juce.com/t/solved-formatmanager-createreaderfor-and-memoryinputstream-question/45394/3 "2021-04-07T15:18:46Z")

</div>

Ah, missed that… That explains it, thanks!
