Skip to content

Instantly share code, notes, and snippets.

@vinniefalco
Created September 1, 2020 02:07
Show Gist options
  • Save vinniefalco/c999a693e46e2dec072c68ed60068f73 to your computer and use it in GitHub Desktop.
Save vinniefalco/c999a693e46e2dec072c68ed60068f73 to your computer and use it in GitHub Desktop.
/** 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
@endcode
@par Preconditions
@code
r != nullptr
@endcode
@par Exception Safety
No-throw guarantee.
@param r A pointer to the memory resource to use.
This may not be null.
*/
template<class T
#ifndef BOOST_JSON_DOCS
, class = typename std::enable_if<
std::is_convertible<T*,
memory_resource*>::value>::type
#endif
>
storage_ptr(T* r) noexcept
: i_(reinterpret_cast<std::uintptr_t>(
static_cast<memory_resource *>(r)) +
(json::is_deallocate_trivial<T>::value ? 2 : 0))
{
BOOST_ASSERT(r);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment