22#ifndef LELY_UTIL_C_TYPE_HPP_
23#define LELY_UTIL_C_TYPE_HPP_
82 operator()(T* p)
const {
91template <
class T,
class...
Args>
92inline ::std::shared_ptr<T>
94 return ::std::shared_ptr<T>(
new T(::std::forward<Args>(
args)...),
109template <
class T,
class...
Args>
125 typedef typename c_type_traits<T>::value_type c_value_type;
126 typedef typename c_type_traits<T>::reference c_reference;
127 typedef typename c_type_traits<T>::const_reference c_const_reference;
128 typedef typename c_type_traits<T>::pointer c_pointer;
129 typedef typename c_type_traits<T>::const_pointer c_const_pointer;
131 operator c_value_type()
const noexcept {
return c_ref(); }
132 operator c_reference()
noexcept {
return c_ref(); }
133 operator c_const_reference()
const noexcept {
return c_ref(); }
141 c_ref()
const noexcept {
147 return reinterpret_cast<c_pointer
>(
this);
151 c_ptr()
const noexcept {
152 return reinterpret_cast<c_const_pointer
>(
this);
176 typedef typename c_type_traits<T>::value_type c_value_type;
177 typedef typename c_type_traits<T>::reference c_reference;
178 typedef typename c_type_traits<T>::const_reference c_const_reference;
179 typedef typename c_type_traits<T>::pointer c_pointer;
180 typedef typename c_type_traits<T>::const_pointer c_const_pointer;
182 operator c_value_type()
const noexcept {
return c_ref(); }
183 operator c_reference()
noexcept {
return c_ref(); }
184 operator c_const_reference()
const noexcept {
return c_ref(); }
192 c_ref()
const noexcept {
198 return reinterpret_cast<c_pointer
>(
this);
202 c_ptr()
const noexcept {
203 return reinterpret_cast<c_const_pointer
>(
this);
229 template <
class...
Args>
232 impl::throw_bad_init();
251 typedef typename c_type_traits<T>::value_type c_value_type;
252 typedef typename c_type_traits<T>::reference c_reference;
253 typedef typename c_type_traits<T>::const_reference c_const_reference;
254 typedef typename c_type_traits<T>::pointer c_pointer;
255 typedef typename c_type_traits<T>::const_pointer c_const_pointer;
257 operator c_reference()
noexcept {
return c_ref(); }
258 operator c_const_reference()
const noexcept {
return c_ref(); }
266 c_ref()
const noexcept {
272 return reinterpret_cast<c_pointer
>(
this);
276 c_ptr()
const noexcept {
277 return reinterpret_cast<c_const_pointer
>(
this);
291 operator new(std::size_t size) {
292 void* ptr =
operator new(size, ::std::nothrow);
298 operator new(std::size_t, const ::std::nothrow_t&)
noexcept {
303 operator delete(
void* ptr)
noexcept {
304 operator delete(ptr, ::std::nothrow);
308 operator delete(
void* ptr, const ::std::nothrow_t&)
noexcept {
324 void*
operator new[](std::size_t) =
delete;
325 void*
operator new[](std::size_t, const ::std::nothrow_t&) =
delete;
326 void operator delete[](
void*) =
delete;
327 void operator delete[](
void*, const ::std::nothrow_t&) =
delete;
330 template <
class...
Args>
333 impl::throw_bad_init();
351 typedef T value_type;
352 typedef value_type& reference;
353 typedef const value_type& const_reference;
354 typedef value_type* pointer;
355 typedef const value_type* const_pointer;
359 return operator new(
sizeof(T), ::std::nothrow);
363 free(
void* ptr)
noexcept {
364 operator delete(ptr, ::std::nothrow);
368 init(pointer p)
noexcept {
373 init(pointer p,
const T& val)
noexcept {
374 return new (
static_cast<void*
>(p)) T(val);
378 fini(pointer p)
noexcept {
383 copy(pointer
p1, const_pointer
p2)
noexcept {
389 move(pointer
p1, pointer
p2)
noexcept {
390 *
p1 = ::std::move(*
p2);
411 return operator new(0, ::std::nothrow);
415 free(
void* ptr)
noexcept {
416 operator delete(ptr, ::std::nothrow);
420 init(pointer p)
noexcept {
425 fini(pointer p)
noexcept {
430 copy(pointer p1, const_pointer p2)
noexcept {
437 move(pointer p1, pointer p2)
noexcept {
unique_c_ptr< T > make_unique_c(Args &&... args)
Creates an instance of a trivial, standard layout or incomplete C type and wraps it in a lely::unique...
::std::unique_ptr< T, delete_c_type< T > > unique_c_ptr
A specialization of std::unique_ptr for trivial, standard layout or incomplete C types,...
inline ::std::shared_ptr< T > make_shared_c(Args &&... args)
Creates an instance of a trivial, standard layout or incomplete C type and wraps it in a std::shared_...
The type of objects thrown as exceptions to report a failure to copy an instantiation of a C type.
The type of objects thrown as exceptions to report a failure to initialize an instantiation of a C ty...
The type of objects thrown as exceptions to report a failure to move an instantiation of a C type.
The type of objects thrown as exceptions to report a system error with an associated error code.
The base class for a C++ interface to an incomplete C type.
The base class for a C++ interface to a standard layout C type.
@ ERRNUM_NOMEM
Not enough space.
errnum_t get_errnum(void)
Returns the last (thread-specific) platform-independent error number set by a system call or library ...
This header file is part of the utilities library; it contains the C++ exception declarations.
#define throw_or_abort(e)
If exceptions are disabled, aborts the process instead of throwing an exception.
A class template supplying a uniform interface to certain attributes of C types.
The deleter for trivial, standard layout and incomplete C types.
The base class for a C++ interface to a trivial C type.