Classes | Typedefs | Functions
StringStorage.hh File Reference
#include "ranges.hh"
#include <cstdlib>
#include <memory>
#include <string_view>
Include dependency graph for StringStorage.hh:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.


struct  FreeStringStorage
 StringStorage: Acts like a 'const char*', but in addition calls free() when the pointer goes out of scope. More...


using StringStorage = std::unique_ptr< char, FreeStringStorage >


StringStorage allocate_string_storage (size_t size)
 Allocate a 'StringStorage' large enough for 'size' characters.
StringStorage allocate_c_string (std::string_view s)
 Allocate memory for and copy a c-string (zero-terminated string).

Typedef Documentation

◆ StringStorage

using StringStorage = std::unique_ptr<char, FreeStringStorage>

Definition at line 17 of file StringStorage.hh.

Function Documentation

◆ allocate_c_string()

StringStorage allocate_c_string ( std::string_view  s)

Allocate memory for and copy a c-string (zero-terminated string).

This function is similar to strdup(), except that this function:

  • takes a 'string_view' instead of a 'const char*' parameter.
  • returns a 'StringStorage' instead of 'char*'.

Definition at line 32 of file StringStorage.hh.

References allocate_string_storage(), and ranges::copy().

◆ allocate_string_storage()

StringStorage allocate_string_storage ( size_t  size)

Allocate a 'StringStorage' large enough for 'size' characters.

Definition at line 22 of file StringStorage.hh.

Referenced by allocate_c_string(), make_string_storage(), and TemporaryString::TemporaryString().