protozero::data_view Class Reference

`#include <data_view.hpp>`

## Public Member Functions

constexpr | data_view () noexcept=default
constexpr | data_view (const char *ptr, std::size_t length) noexcept
| data_view (const std::string &str) noexcept
| data_view (const char *ptr) noexcept
void | swap (data_view &other) noexcept
constexpr const char * | data () const noexcept
| Return pointer to data.
constexpr std::size_t | size () const noexcept
| Return length of data in bytes.
constexpr bool | empty () const noexcept
| Returns true if size is 0.
std::string | to_string () const
| operator std::string () const
int | compare (data_view other) const

## Detailed Description

Holds a pointer to some data and a length.

This class is supposed to be compatible with the std::string_view that will be available in C++17.

## Constructor & Destructor Documentation

## data_view() [1/4]

constexpr protozero::data_view::data_view | ( |  | ) |

default noexcept

Default constructor. Construct an empty data_view.

## data_view() [2/4]

constexpr protozero::data_view::data_view | ( | const char * | ptr,
|  | std::size_t | length
| ) |  |

inline noexcept

Create data_view from pointer and size.

Parameters

  ptr | Pointer to the data.
  length | Length of the data.

## data_view() [3/4]

protozero::data_view::data_view | ( | const std::string & | str | ) |

inline noexcept

Create data_view from string.

Parameters

  str | String with the data.

## data_view() [4/4]

protozero::data_view::data_view | ( | const char * | ptr | ) |

inline noexcept

Create data_view from zero-terminated string.

Parameters

  ptr | Pointer to the data.

## Member Function Documentation

## compare()

int protozero::data_view::compare | ( | data_view | other | ) | const

inline

Compares the contents of this object with the given other object.

Returns
  0 if they are the same, <0 if this object is smaller than the other or >0 if it is larger. If both objects have the same size returns <0 if this object is lexicographically before the other, >0 otherwise.

Precondition
  Must not be default constructed data_view.

## operator std::string()

protozero::data_view::operator std::string | ( |  | ) | const

inline explicit

Convert data view to string.

Precondition
  Must not be default constructed data_view.

## swap()

void protozero::data_view::swap | ( | data_view & | other | ) |

inline noexcept

Swap the contents of this object with the other.

Parameters

  other | Other object to swap data with.

## to_string()

std::string protozero::data_view::to_string | ( |  | ) | const

inline

Convert data view to string.

Precondition
  Must not be default constructed data_view.

Deprecated:
  to_string() is not available in C++17 string_view so it should not be used to make conversion to that class easier in the future.

The documentation for this class was generated from the following file:

- include/protozero/data_view.hpp