iffl  1.3.4
Implements Intrusive Flat Forward List container
Classes | Namespaces | Macros | Typedefs | Functions
iffl_common.h File Reference

Common definitions, utility functions and vocabulary types. More...

#include <type_traits>
#include <vector>
#include <tuple>
#include <algorithm>
#include <utility>
#include <atomic>
#include <cerrno>
#include <typeinfo>
#include <memory>
#include <cstring>
#include <memory_resource>
#include <cstdio>
#include <intrin.h>

Go to the source code of this file.

Classes

class  iffl::scope_guard< G >
 template class that can be parametrized with a functor or a lambda that it will call in destructor. More...
 
class  iffl::attach_buffer
 Helper class used as a parameter in flat_forward_list constructor to designate that it should take ownership of the buffer rather than make a copy. More...
 
class  iffl::range
 Vocabulary type that describes a sub-buffer in a larger buffer, and portion of that sub-buffer actually used by the data. More...
 
class  iffl::range_with_alighment< ALIGNMENT_V >
 Vocabulary type that describes a sub-buffer in a larger buffer and portion of that sub-buffer actually used by the data. More...
 
class  iffl::offset_with_aligment< ALIGNMENT_V >
 Vocabulary type that describes an offset in a larger buffer and template parameter that specifies element's type alignment requirements. More...
 
class  iffl::size_with_padding< ALIGNMENT_V >
 Vocabulary type that describes an size and template parameter that specifies element's type alignment requirements. More...
 
class  iffl::flat_forward_list_sizes< ALIGNMENT_V >
 Describes buffer used by container. More...
 
class  iffl::zero_then_variadic_args_t
 Tag type for value - initializing first, constructing second from remaining arguments. More...
 
class  iffl::one_then_variadic_args_t
 Tag type for constructing first from one argument, constructing second from remaining arguments. More...
 
class  iffl::compressed_pair< T1, T2, bool >
 Empty Base Class Optimization EBCO helper. More...
 
class  iffl::compressed_pair< T1, T2, false >
 Specialization for the case when Empty Base Class Optimization EBCO would not work. More...
 
class  iffl::buffer_t< T >
 A set of pointers describing state of the buffer containing flat forward list. More...
 

Namespaces

 iffl::mpl
 intrusive flat forward list
 
 iffl
 intrusive flat forward list
 

Macros

#define FFL_PMR   std::pmr
 In MSVC pmr was already shipped.
 
#define FFL_UNALIGNED   __unaligned
 On vc use __unaligned keyword to signify that pointer is pointing to a not properly aligned data. __unaligned is not supported on x86.
 
#define FFL_PLATFORM_FAIL_FAST(EC)   {__debugbreak();__fastfail(EC);}
 In MSVC define to intrinsics that terminate the process.
 
#define FFL_ALLIGNED_ALLOC(BYTES, ALIGNMENT)   _aligned_malloc(BYTES, ALIGNMENT)
 In MSVC define to function that allocates aligned buffer.
 
#define FFL_ALLIGNED_FREE(PTR)   _aligned_free(PTR)
 In MSVC define to function matching to _aligned_malloc.
 
#define FFL_FAST_FAIL(EC)   {FFL_PLATFORM_FAIL_FAST(EC);}
 Fail fast with error code. More...
 
#define FFL_CRASH_APPLICATION()   FFL_FAST_FAIL(ENOTRECOVERABLE)
 Fail fast with error ENOTRECOVERABLE(127 or 0x7f)
 
#define FFL_CODDING_ERROR_IF(C)   if (C) {FFL_FAST_FAIL(ENOTRECOVERABLE);} else {;}
 If expression is true then fail fast with error ENOTRECOVERABLE(127 or 0x7f) More...
 
#define FFL_CODDING_ERROR_IF_NOT(C)   if (C) {;} else {FFL_FAST_FAIL(ENOTRECOVERABLE);}
 If expression is false then fail fast with error ENOTRECOVERABLE(127 or 0x7f) More...
 
#define FFL_FIELD_OFFSET(T, F)   (((char const *)(&((T *)nullptr)->F)) - (char const *)nullptr)
 Field offset in the structure. More...
 
#define FFL_SIZE_THROUGH_FIELD(T, F)   (FFL_FIELD_OFFSET(T, F) + sizeof(((T *)nullptr)->F))
 Field offset in the structure plus field size. Offset to the start of padding [if any] for the next field [if any]. More...
 
#define FFL_PADDING_OFFSET_AFTER_FIELD(T, F)   FFL_SIZE_THROUGH_FIELD(T, F)
 Offset to the start of padding [if any] for the next field [if any]. More...
 
#define FFL_PADDING_BETWEEN_FIELDS_UNSAFE(T, F1, F2)   (FFL_FIELD_OFFSET(T, F2) - FFL_SIZE_THROUGH_FIELD(T, F1))
 Size of padding [if any] between two fields. Does not validate that F2 is following after F1 in the structure. More...
 
#define FFL_PADDING_BETWEEN_FIELDS(T, F1, F2)   ([] {static_assert(FFL_FIELD_OFFSET(T, F1) <= FFL_FIELD_OFFSET(T, F2), "F1 must have lower offset in structure than F2"); }, FFL_PADDING_BETWEEN_FIELDS_UNSAFE(T, F1, F2))
 Size of padding [if any] between two fields. Validate that F2 is following after F1 in the structure. More...
 
#define FFL_FIELD_PTR_TO_OBJ_PTR(T, F, P)   ((T *)((char const *)(P) - FFL_FIELD_OFFSET(T, F)))
 Calculates pointer to the beginning of the structure from the pointer to a field in that structure. More...
 

Typedefs

using iffl::buffer_ref = buffer_t< char >
 Non const flat forward list buffer.
 
using iffl::buffer_view = buffer_t< char const >
 Const flat forward list buffer.
 

Functions

template<typename T >
constexpr void iffl::unused_variable ([[maybe_unused]] T const &)
 Restore saved min and max definition. More...
 
template<typename T >
constexpr void iffl::unused_expression_result ([[maybe_unused]] T const &)
 Silence sensitizers warning about unused result of expression. More...
 
size_t const iffl::ptr_to_size (void const *const ptr)
 Reinterprets pointer to void value as size_t value. More...
 
void *const iffl::size_to_ptr (size_t size)
 Reinterprets size_t value as pointer to void. More...
 
constexpr size_t iffl::roundup_size_to_alignment (size_t size, size_t alignment) noexcept
 Rounds up size to specified alignment. More...
 
template<typename T >
constexpr size_t iffl::roundup_size_to_alignment (size_t size) noexcept
 Rounds up size to specified alignment. More...
 
void * iffl::roundup_ptr_to_alignment (void *ptr, size_t alignment) noexcept
 Rounds up pointer to specified alignment. More...
 
template<typename T >
void * iffl::roundup_ptr_to_alignment (void *ptr) noexcept
 Rounds up pointer to specified alignment. More...
 
void const * iffl::roundup_ptr_to_alignment (void const *ptr, size_t alignment) noexcept
 Rounds up pointer to specified alignment. More...
 
template<typename T >
void const * iffl::roundup_ptr_to_alignment (void const *ptr) noexcept
 Rounds up pointer to specified alignment. More...
 
void iffl::copy_data (char *to_buffer, char const *from_buffer, size_t length) noexcept
 copies length bytes from from_buffer to to_buffer. source and destination buffers cannot overlap More...
 
void iffl::move_data (char *to_buffer, char const *from_buffer, size_t length) noexcept
 copies length bytes from from_buffer to to_buffer. source and destination buffers can overlap More...
 
void iffl::fill_buffer (char *buffer, int value, size_t length) noexcept
 sets "length" consecutive bytes of "to_buffer" to "value". More...
 
void iffl::zero_buffer (char *buffer, size_t length) noexcept
 sets "length" consecutive bytes of "to_buffer" to 0. More...
 
size_t iffl::distance (void const *begin, void const *end) noexcept
 sets "length" consecutive bytes of "to_buffer" to 0. More...
 
template<typename T >
char * iffl::cast_to_char_ptr (T *p) noexcept
 Helper method to cast a pointer to a char *. More...
 
template<typename T >
void * iffl::cast_to_void_ptr (T *p) noexcept
 Helper method to cast a pointer to a void *. More...
 
template<typename G >
constexpr auto iffl::make_scope_guard (G &&g)
 Factory method for scoped_guard. More...
 

Detailed Description

Common definitions, utility functions and vocabulary types.

Author
Vladimir Petter

iffl github

Macro Definition Documentation

◆ FFL_CODDING_ERROR_IF

#define FFL_CODDING_ERROR_IF (   C)    if (C) {FFL_FAST_FAIL(ENOTRECOVERABLE);} else {;}

If expression is true then fail fast with error ENOTRECOVERABLE(127 or 0x7f)

Parameters
Cexpression that we are asserting

◆ FFL_CODDING_ERROR_IF_NOT

#define FFL_CODDING_ERROR_IF_NOT (   C)    if (C) {;} else {FFL_FAST_FAIL(ENOTRECOVERABLE);}

If expression is false then fail fast with error ENOTRECOVERABLE(127 or 0x7f)

Parameters
Cexpression that we are asserting

◆ FFL_FAST_FAIL

#define FFL_FAST_FAIL (   EC)    {FFL_PLATFORM_FAIL_FAST(EC);}

Fail fast with error code.

Parameters
EC- fail fast error code

◆ FFL_FIELD_OFFSET

#define FFL_FIELD_OFFSET (   T,
 
)    (((char const *)(&((T *)nullptr)->F)) - (char const *)nullptr)

Field offset in the structure.

Parameters
Ttype field is member of
Ffield name

◆ FFL_FIELD_PTR_TO_OBJ_PTR

#define FFL_FIELD_PTR_TO_OBJ_PTR (   T,
  F,
 
)    ((T *)((char const *)(P) - FFL_FIELD_OFFSET(T, F)))

Calculates pointer to the beginning of the structure from the pointer to a field in that structure.

Parameters
Ttype fields are members of
Ffield name
Ppointer to the field

◆ FFL_PADDING_BETWEEN_FIELDS

#define FFL_PADDING_BETWEEN_FIELDS (   T,
  F1,
  F2 
)    ([] {static_assert(FFL_FIELD_OFFSET(T, F1) <= FFL_FIELD_OFFSET(T, F2), "F1 must have lower offset in structure than F2"); }, FFL_PADDING_BETWEEN_FIELDS_UNSAFE(T, F1, F2))

Size of padding [if any] between two fields. Validate that F2 is following after F1 in the structure.

Parameters
Ttype fields are members of
F1first field name
F2second field name

◆ FFL_PADDING_BETWEEN_FIELDS_UNSAFE

#define FFL_PADDING_BETWEEN_FIELDS_UNSAFE (   T,
  F1,
  F2 
)    (FFL_FIELD_OFFSET(T, F2) - FFL_SIZE_THROUGH_FIELD(T, F1))

Size of padding [if any] between two fields. Does not validate that F2 is following after F1 in the structure.

Parameters
Ttype fields are members of
F1first field name
F2second field name

◆ FFL_PADDING_OFFSET_AFTER_FIELD

#define FFL_PADDING_OFFSET_AFTER_FIELD (   T,
 
)    FFL_SIZE_THROUGH_FIELD(T, F)

Offset to the start of padding [if any] for the next field [if any].

Parameters
Ttype field is member of
Ffield name

◆ FFL_SIZE_THROUGH_FIELD

#define FFL_SIZE_THROUGH_FIELD (   T,
 
)    (FFL_FIELD_OFFSET(T, F) + sizeof(((T *)nullptr)->F))

Field offset in the structure plus field size. Offset to the start of padding [if any] for the next field [if any].

Parameters
Ttype field is member of
Ffield name