Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Vinnie Falco vinniefalco

🏠
Working from home
View GitHub Profile
View gist:c05e72b35914306876f9c1c2292ef690
static
void
serialize_impl(
string& s,
serializer& sr)
{
// serialize to a small buffer
// to avoid most reallocations
char buf[16384];
string_view sv;
View gist:c4635c98ad51dee7eec935a9661356c0
/** Return an @ref array pointer if this is an array, else return `nullptr`
If `this->kind() == kind::array`, then a pointer
to the underlying array is returned. Otherwise,
`nullptr` is returned.
@par Example
The semantics of the function allow the return
value to be used in a conditional expression as
View gist:56e3709db3fde2951a71859cd2a623ea
void*
static_resource::
do_allocate(
std::size_t n,
std::size_t align)
{
std::size_t const extra = (
align * ((i_ + align - 1) / align)) - i_;
if( extra > n_ ||
n > n_ ||
View gist:b1b5a344c8382491590f58d203c58007
void*
static_resource::
do_allocate(
std::size_t n,
std::size_t align)
{
auto const i = reinterpret_cast<
std::uintptr_t>(buffer_ + used_);
std::size_t const extra = (
align * ((i + align - 1) / align)) - i;
View gist:c999a693e46e2dec072c68ed60068f73
/** Constructor
This constructs a non-owning pointer that
points to the specified memory resource `r`.
The caller is responsible for maintaining the
lifetime of the pointed-to @ref memory_resource.
@par Constraints
@code
std::is_convertible< T*, memory_resource* >::value == true
View gist:96a14e591992e839e99770acc0b54750
A polymorphic allocator constructs with a pointer to a memory resource:
// A type of memory resource
std::pmr::monotonic_buffer_resource mr;
// Construct a vector using the monotonic buffer resource
std::pmr::vector< T > v1( std::pmr::polymorphic_allocator< T >(&mr) );
// Or this way, since construction from memory_resource* is implicit:
std::pmr::vector< T > v2( &mr );
View gist:67ee55deda16b9fe5fddb37256266cd2
/** Push an object formed by popping `n` key/value pairs from the stack.
This function pushes an @ref object value
onto the stack. The object is formed by first
popping the top `n` key/value pairs from the
stack. If the stack contains fewer than `n`
key/value pairs, or if any of the top `n` key/value
pairs on the stack does not consist of exactly one
key followed by one value, the behavior is undefined.
\n
View gist:b41bd9e0358518a568e03efab6e6daec
/** Push an object formed by popping `n` key/value pairs from the stack.
This function pushes an @ref object value
onto the stack. The object is formed by first
popping the top `n` key/value pairs from the
stack. If the stack contains fewer than `n`
key/value pairs, or if any of the top `n` key/value
pairs on the stack does not consist of exactly one
key followed by one value, the behavior is undefined.
\n
View gist:cf95e017c428e02e969e186f3248b9c3
/** Push an array formed by popping `n` values from the stack.
This function pushes an @ref array value
onto the stack. The array is formed by first
popping the top `n` values from the stack.
If the stack contains fewer than `n` values,
or if any of the top `n` values on the stack
is a key, the behavior is undefined.
@param n The number of values to pop from the
View gist:0a23d999ae06ea18e70d0bbd9cdbf1ae
// Construct the builder using a local buffer
char temp[4096];
value_builder vb( storage_ptr(), temp, sizeof(temp) );
// Create a monotonic resource with a local initial buffer
char buf[4096];
monotonic_resource mr( buf, sizeof(buf) );
// The builder will create a value using `mr`
vb.reset(&mr);
You can’t perform that action at this time.