std::return_temporary_buffer - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::return_temporary_buffer

From cppreference.com
< cpp‎ | memory

Defined in header `<memory>` |  |
template< class T > void return_temporary_buffer( T* p ); |  | (deprecated in C++17)

Deallocates storage previously allocated with std::get_temporary_buffer.

### [edit] Parameters

p | - | the pointer previously returned by std::get_temporary_buffer and not invalidated by an earlier call to `return_temporary_buffer`

### [edit] Return value

(none)

### Exceptions (none) | (since C++17)

### [edit] Example

[edit]
Run this code

    #include <algorithm>
    #include <iostream>
    #include <memory>
    #include <string>
    #include <iterator>

    int main()
    {
        const std::string s[] = {"string", "1", "test", "..."};
        const auto p = std::get_temporary_buffer<std::string>(4);
        // requires that p.first is passed to return_temporary_buffer
        // (beware of early exit points and exceptions)

        std::copy(s, s + p.second,
                  std::raw_storage_iterator<std::string*, std::string>(p.first));
        // requires that each string in p is individually destroyed
        // (beware of early exit points and exceptions)

        std::copy(p.first, p.first + p.second,
                  std::ostream_iterator<std::string>{std::cout, "\n"});

        std::for_each(p.first, p.first + p.second, [](std::string& e) {
            e.~basic_string<char>();
        });

        std::return_temporary_buffer(p.first);
    }

Output:

    string
    1
    test
    ...

### [edit] See also

get_temporary_buffer (deprecated in C++17) | obtains uninitialized storage (function template) [edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/memory/return_temporary_buffer&oldid=86277"