16 Buffers [buffer]

16.11 Buffer creation functions [buffer.creation]

In the functions below, T shall be a trivially copyable or standard-layout type (C++ 2014 [basic.types]).

For the function overloads below that accept an argument of type vector<>, the buffer objects returned are invalidated by any vector operation that also invalidates all references, pointers and iterators referring to the elements in the sequence (C++ 2014 [vector]).

For the function overloads below that accept an argument of type basic_string<>, the buffer objects returned are invalidated according to the rules defined for invalidation of references, pointers and iterators referring to elements of the sequence (C++ 2014 [string.require]).

mutable_buffer buffer(void* p, size_t n) noexcept;

Returns: mutable_buffer(p, n).

const_buffer buffer(const void* p, size_t n) noexcept;

Returns: const_buffer(p, n).

mutable_buffer buffer(const mutable_buffer& b) noexcept;

Returns: b.

mutable_buffer buffer(const mutable_buffer& b, size_t n) noexcept;

Returns: mutable_buffer(b.data(), min(b.size(), n)).

const_buffer buffer(const const_buffer& b) noexcept;

Returns: b.

const_buffer buffer(const const_buffer& b, size_t n) noexcept;

Returns: const_buffer(b.data(), min(b.size(), n)).

template<class T, size_t N> mutable_buffer buffer(T (&data)[N]) noexcept; template<class T, size_t N> const_buffer buffer(const T (&data)[N]) noexcept; template<class T, size_t N> mutable_buffer buffer(array<T, N>& data) noexcept; template<class T, size_t N> const_buffer buffer(array<const T, N>& data) noexcept; template<class T, size_t N> const_buffer buffer(const array<T, N>& data) noexcept; template<class T, class Allocator> mutable_buffer buffer(vector<T, Allocator>& data) noexcept; template<class T, class Allocator> const_buffer buffer(const vector<T, Allocator>& data) noexcept; template<class CharT, class Traits, class Allocator> mutable_buffer buffer(basic_string<CharT, Traits, Allocator>& data) noexcept; template<class CharT, class Traits, class Allocator> const_buffer buffer(const basic_string<CharT, Traits, Allocator>& data) noexcept; template<class CharT, class Traits> const_buffer buffer(basic_string_view<CharT, Traits> data) noexcept;

Returns:

buffer(
  begin(data) != end(data) ? std::addressof(*begin(data)) : nullptr,
  (end(data) - begin(data)) * sizeof(*begin(data)));

template<class T, size_t N> mutable_buffer buffer(T (&data)[N], size_t n) noexcept; template<class T, size_t N> const_buffer buffer(const T (&data)[N], size_t n) noexcept; template<class T, size_t N> mutable_buffer buffer(array<T, N>& data, size_t n) noexcept; template<class T, size_t N> const_buffer buffer(array<const T, N>& data, size_t n) noexcept; template<class T, size_t N> const_buffer buffer(const array<T, N>& data, size_t n) noexcept; template<class T, class Allocator> mutable_buffer buffer(vector<T, Allocator>& data, size_t n) noexcept; template<class T, class Allocator> const_buffer buffer(const vector<T, Allocator>& data, size_t n) noexcept; template<class CharT, class Traits, class Allocator> mutable_buffer buffer(basic_string<CharT, Traits, Allocator>& data, size_t n) noexcept; template<class CharT, class Traits, class Allocator> const_buffer buffer(const basic_string<CharT, Traits, Allocator>& data, size_t n) noexcept; template<class CharT, class Traits> const_buffer buffer(basic_string_view<CharT, Traits> data, size_t n) noexcept;

Returns: buffer(buffer(data), n).