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(); }
140 c_ref()
const noexcept {
146 return reinterpret_cast<c_pointer
>(
this);
150 c_ptr()
const noexcept {
151 return reinterpret_cast<c_const_pointer
>(
this);
174 typedef typename c_type_traits<T>::value_type c_value_type;
175 typedef typename c_type_traits<T>::reference c_reference;
176 typedef typename c_type_traits<T>::const_reference c_const_reference;
177 typedef typename c_type_traits<T>::pointer c_pointer;
178 typedef typename c_type_traits<T>::const_pointer c_const_pointer;
180 operator c_value_type()
const noexcept {
return c_ref(); }
181 operator c_reference()
noexcept {
return c_ref(); }
182 operator c_const_reference()
const noexcept {
return c_ref(); }
189 c_ref()
const noexcept {
195 return reinterpret_cast<c_pointer
>(
this);
199 c_ptr()
const noexcept {
200 return reinterpret_cast<c_const_pointer
>(
this);
225 template <
class... Args>
228 impl::throw_bad_init();
247 typedef typename c_type_traits<T>::value_type c_value_type;
248 typedef typename c_type_traits<T>::reference c_reference;
249 typedef typename c_type_traits<T>::const_reference c_const_reference;
250 typedef typename c_type_traits<T>::pointer c_pointer;
251 typedef typename c_type_traits<T>::const_pointer c_const_pointer;
253 operator c_reference()
noexcept {
return c_ref(); }
254 operator c_const_reference()
const noexcept {
return c_ref(); }
261 c_ref()
const noexcept {
267 return reinterpret_cast<c_pointer
>(
this);
271 c_ptr()
const noexcept {
272 return reinterpret_cast<c_const_pointer
>(
this);
285 operator new(std::size_t size) {
286 void* ptr =
operator new(size, ::std::nothrow);
292 operator new(std::size_t, const ::std::nothrow_t&)
noexcept {
297 operator delete(
void* ptr)
noexcept {
298 operator delete(ptr, ::std::nothrow);
302 operator delete(
void* ptr, const ::std::nothrow_t&)
noexcept {
318 static void*
operator new[](std::size_t) =
delete;
319 static void*
operator new[](std::size_t, const ::std::nothrow_t&) =
delete;
320 static void operator delete[](
void*) =
delete;
321 static void operator delete[](
void*, const ::std::nothrow_t&) =
delete;
324 template <
class... Args>
327 impl::throw_bad_init();
345 typedef T value_type;
346 typedef value_type& reference;
347 typedef const value_type& const_reference;
348 typedef value_type* pointer;
349 typedef const value_type* const_pointer;
353 return operator new(
sizeof(T), ::std::nothrow);
357 free(
void* ptr)
noexcept {
358 operator delete(ptr, ::std::nothrow);
362 init(pointer p)
noexcept {
367 init(pointer p,
const T& val)
noexcept {
368 return new (
static_cast<void*
>(p)) T(val);
372 fini(pointer p)
noexcept {
377 copy(pointer p1, const_pointer p2)
noexcept {
383 move(pointer p1, pointer p2)
noexcept {
384 *p1 = ::std::move(*p2);
395 typedef void value_type;
398 typedef __type& reference;
399 typedef const __type& const_reference;
400 typedef value_type* pointer;
401 typedef const value_type* const_pointer;
405 return operator new(0, ::std::nothrow);
409 free(
void* ptr)
noexcept {
410 operator delete(ptr, ::std::nothrow);
414 init(pointer p)
noexcept {
419 fini(pointer p)
noexcept {
424 copy(pointer p1, const_pointer p2)
noexcept {
431 move(pointer p1, pointer p2)
noexcept {
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.
Global namespace for the Lely Industries N.V. libraries.
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_...
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.