chsvlib
chsv helper source code
chsvmemex.h File Reference

Advanced functionality and C++ objects for working with memory. More...

#include "chsvmem.h"
#include "chsvexception.h"
#include "chsvmetafun.h"

Classes

struct  iterator_range< Iterator >
 An auxiliary class for a range given by a pair of iterators. More...
 
struct  allocator< void >
 A Chusov::Memory::allocator class template specialization for pointers of void* type. More...
 
struct  allocator< void >::rebind
 
struct  allocator< T >
 A class template implementing behavior of the standard allocator interface using the memory management functions of the Chusov::Memory namespace. More...
 
struct  allocator< T >::rebind< U >
 
struct  secure_allocator< T >
 A class template redefining the behavior of the Chusov::Memory::allocator class template so that the deallocation function randomizes the memory before the deallocation. More...
 
class  generating_input_iterator< GeneratingFunctor, ValueType >
 Implements semantics of an input iterator to providing access to elements generated by a given functional object. More...
 
struct  transforming_iterator< BaseIterator, TransformingFunctor >
 
struct  subtuple< Tpl, Begin, End >
 Defines a type field which is an alias for a subtuple consisting of elements within the specified range of a given tuple. More...
 
struct  raw_pointer_iterator< T * >
 An wrapper over a raw pointer considered as an iterator used to resolve security warnings produced by Microsoft C++ compilers. The class is defined independently of a compiler used. More...
 
class  sbo_vector< ElementType, sbo_threshold, Allocator >
 Implements a vector with customizable small buffer optimization. More...
 

Namespaces

 Chusov
 Basic chsvlib namespace.
 
 Chusov::Memory
 A namespace of functions and components used to work with memory.
 

Typedefs

template<class value_t , class allocator_t = allocator<value_t>>
using list = std::list< value_t, allocator_t >
 An alias for the standard list container that uses Chusov::Memory::allocator instead of allocator by default.
 
template<class value_t , class allocator_t = allocator<value_t>>
using vector = std::vector< value_t, allocator_t >
 An alias for the standard vector container that uses Chusov::Memory::allocator instead of allocator by default.
 
template<class ... Iterators>
using iterators_size_type = typename std::common_type< typename std::make_unsigned< typename std::iterator_traits< Iterators >::difference_type >::type... >::type
 A SFINAE-friendly alias to a common type which corresponds to unsigned counterparts of difference types of the parameter iterators. More...
 

Functions

template<class IteratorBegin , class IteratorEnd >
iterator_range< std::common_type_t< std::decay_t< IteratorBegin >, std::decay_t< IteratorEnd > > > make_iterator_range (IteratorBegin &&begin_iterator, IteratorEnd &&end_iterator) noexcept(std::is_nothrow_constructible< iterator_range< std::common_type_t< std::decay_t< IteratorBegin >, std::decay_t< IteratorEnd >>>, IteratorBegin && >::value &&std::is_nothrow_constructible< iterator_range< std::common_type_t< std::decay_t< IteratorBegin >, std::decay_t< IteratorEnd >>>, IteratorEnd && >::value)
 Forwards the deduced parameters to the corresponding constructor of the iterator_range class template specialized for the common type of both template arguments. More...
 
template<class Iterator >
iterator_range< Iterator > make_iterator_range (const std::pair< Iterator, Iterator > &range_pair) noexcept(std::is_nothrow_copy_constructible< Iterator >::value)
 Constructs an iterator_range object based on a copy of bounding iterators given by a pair. More...
 
template<class Iterator >
iterator_range< Iterator > make_iterator_range (std::pair< Iterator, Iterator > &&range_pair) noexcept(std::is_nothrow_move_constructible< Iterator >::value)
 Constructs an iterator_range object by taking ownership of bounding iterators given by a pair. More...
 
template<class OtherRange >
iterator_range< typename std::decay< OtherRange >::type::iterator > make_iterator_range (OtherRange &&range) noexcept((std::is_rvalue_reference< OtherRange && >::value &&std::is_nothrow_move_constructible< typename std::decay< OtherRange >::type::iterator >::value)||(std::is_lvalue_reference< OtherRange && >::value &&std::is_nothrow_copy_constructible< typename std::decay< OtherRange >::type::iterator >::value))
 Constructs a range from another range forwarding the call to the corresponding constructor of iterator_range. More...
 
template<class GeneratingFunctor >
auto make_generating_input_iterator (GeneratingFunctor generator)
 A helper function used to create a generating iterator of type generating_input_iterator with deduction of its template parameters prior to C++17. More...
 
template<class BaseRandomAccessIterator , class TransformingFunctor >
transforming_iterator< BaseRandomAccessIterator, TransformingFunctor > operator+ (typename transforming_iterator< BaseRandomAccessIterator, TransformingFunctor >::difference_type n, const transforming_iterator< BaseRandomAccessIterator, TransformingFunctor > &iter)
 Creates a copy of a transforming iterator associated with a position shifted by a specified number to the end. More...
 
template<class BaseIterator , class TransformingFunctor >
transforming_iterator< BaseIterator, typename std::remove_reference< TransformingFunctor >::type > make_transforming_iterator (BaseIterator it, TransformingFunctor &&transformer)
 Returns an instance of transforming_iterator for a given iterator and a transforming Callable object.
 
template<std::size_t Begin, std::size_t End, class Tpl >
constexpr auto make_subtuple (Tpl &&tpl) noexcept(noexcept(Implementation::subtuple< Begin, End >::make(std::forward< Tpl >(tpl)))) -> decltype(Implementation::subtuple< Begin, End >::make(std::forward< Tpl >(tpl)))
 Creates a sub-tuple from elements of a given tuple as specified by a half-range. More...
 
template<std::size_t Begin, std::size_t End, class Tpl >
constexpr auto forward_subtuple (Tpl &&tpl) noexcept(noexcept(Implementation::subtuple< Begin, End >::forward(std::forward< Tpl >(tpl)))) -> decltype(Implementation::subtuple< Begin, End >::forward(std::forward< Tpl >(tpl)))
 Creates a sub-tuple of rvalue references to elements of a given tuple as specified by a half-range. More...
 
template<class T >
constexpr raw_pointer_iterator< T * >::reference operator* (const raw_pointer_iterator< T * > &it) noexcept(noexcept(*it.base()))
 Dereferences a raw_pointer_iterator. More...
 
template<class T >
raw_pointer_iterator< T * > operator++ (raw_pointer_iterator< T * > &it, int) noexcept(noexcept(raw_pointer_iterator< T * >(it)) &&noexcept(++it))
 Postfix increment operation which shifts the iterated position to the right by 1 but returns a new iterator in the pre-increment state. More...
 
template<class T >
raw_pointer_iterator< T * > operator-- (raw_pointer_iterator< T * > &it, int) noexcept(noexcept(raw_pointer_iterator< T * >(it)) &&noexcept(--it))
 Postfix decrement operation which shifts the iterated position to the left by 1 but returns a new iterator in the pre-decrement state. More...
 
template<class T >
constexpr raw_pointer_iterator< T * > operator+ (typename raw_pointer_iterator< T * >::difference_type n, const raw_pointer_iterator< T * > &right) noexcept(noexcept(right+n))
 Adds an offset to an iterator and returns the new raw_pointer_iterator addressing the element at the new offset position. More...
 
template<class T , class U >
constexpr common_difference_type operator- (const raw_pointer_iterator< T * > &left, const raw_pointer_iterator< U * > &right)
 Calculates a difference between two iterators, i.e. between the two underlying pointers. More...
 
template<class T , class U >
constexpr bool operator== (const raw_pointer_iterator< T * > &left, const raw_pointer_iterator< U * > &right) noexcept
 Checks the two iterators for equality. More...
 
template<class T , class U >
constexpr bool operator!= (const raw_pointer_iterator< T * > &left, const raw_pointer_iterator< U * > &right) noexcept
 Checks the two iterators for inequality. More...
 
template<class T , class U >
constexpr bool operator< (const raw_pointer_iterator< T * > &left, const raw_pointer_iterator< U * > &right) noexcept
 Performs the "less-than" comparison of two iterators. More...
 
template<class T , class U >
constexpr bool operator<= (const raw_pointer_iterator< T * > &left, const raw_pointer_iterator< U * > &right) noexcept
 Performs the "less-or-equal-than" comparison of two iterators. More...
 
template<class T , class U >
constexpr bool operator>= (const raw_pointer_iterator< T * > &left, const raw_pointer_iterator< U * > &right) noexcept
 Performs the "greater-or-equal-than" comparison of two iterators. More...
 
template<class T , class U >
constexpr bool operator> (const raw_pointer_iterator< T * > &left, const raw_pointer_iterator< U * > &right) noexcept
 Performs the "greater-than" comparison of two iterators. More...
 
template<class T >
constexpr raw_pointer_iterator< T * > make_raw_pointer_iterator (T *ptr, std::size_t cSize, typename raw_pointer_iterator< T * >::difference_type iOffset) noexcept(noexcept(raw_pointer_iterator< T * >(ptr, cSize, iOffset)))
 The function for creation iterators, which, in essence, are raw pointers, that has an interface compatible with Microsoft stdext::checked_array_iterator. More...
 
template<class Iterator >
constexpr unspecified offset_iterator_begin (Iterator it) noexcept
 Returns an object of an unspecified type which is an iterator of the same category as the parameter but redefines increment, decrement and comparison operators to keep the current offset from the initial position. More...
 
template<class Iterator >
constexpr auto offset_iterator_end (Iterator it, difference_type offset) noexcept
 Returns an object of an unspecified type which is an iterator of the same category as the parameter but redefines the respective comparison operators to keep the current offset from the initial position given parametrically. More...
 
template<class InputIterator , class OutputIterator >
OutputIterator copy_n (InputIterator input, std::size_t size, OutputIterator output) noexcept(std::is_nothrow_copy_assignable< typename std::iterator_traits< OutputIterator >::value_type >::value)
 Copy-assigns a given number of elements starting from one referred to by an input iterator to a place addressed by an output iterator. More...
 
template<class InputIterator , class OutputIterator >
OutputIterator copy (InputIterator start, InputIterator end, OutputIterator output) noexcept(std::is_nothrow_copy_assignable< typename std::iterator_traits< OutputIterator >::value_type >::value)
 Copy-assigns a sequence of elements addressed by a pair of input iterators to a destination specified by an output iterator. More...
 
template<class InputIterator , class OutputIterator >
OutputIterator move_n (InputIterator input, std::size_t size, OutputIterator output) noexcept(std::is_nothrow_move_assignable< typename std::iterator_traits< OutputIterator >::value_type >::value)
 Move-assigns a given number of elements starting from one referred to by an input iterator to a place addressed by an output iterator. More...
 
template<class InputIterator , class OutputIterator >
void move (InputIterator start, InputIterator end, OutputIterator output) noexcept(std::is_nothrow_move_assignable< typename std::iterator_traits< OutputIterator >::value_type >::value)
 Move-assigns a sequence of elements addressed by a pair of input iterators to a destination specified by an output iterator. More...
 
template<class InputIterator , class OutputIterator >
OutputIterator construct_copy_n (InputIterator input, std::size_t size, OutputIterator output) noexcept(std::is_nothrow_copy_constructible< typename std::iterator_traits< OutputIterator >::value_type >::value)
 Copy-constructs a given number of elements starting from one referred to by an input iterator in the destination addressed by an output iterator. More...
 
template<class InputIterator , class OutputIterator >
OutputIterator construct_copy (InputIterator start, InputIterator end, OutputIterator output) noexcept(std::is_nothrow_copy_constructible< typename std::iterator_traits< OutputIterator >::value_type >::value)
 Copy-constructs a sequence of elements associated with an output iterator from an input sequence addressed by a pair of input iterators. More...
 
template<class InputIterator , class OutputIterator >
OutputIterator construct_move_n (InputIterator input, std::size_t size, OutputIterator output) noexcept(std::is_nothrow_move_constructible< typename std::iterator_traits< OutputIterator >::value_type >::value)
 Move-constructs a given number of elements starting from one referred to by an input iterator in the destination addressed by an output iterator. More...
 
template<class InputIterator , class OutputIterator >
OutputIterator construct_move (InputIterator start, InputIterator end, OutputIterator output) noexcept(std::is_nothrow_move_constructible< typename std::iterator_traits< OutputIterator >::value_type >::value)
 Move-constructs a sequence of elements in a destination specified by an output iterator from an input sequence addressed by a pair of input iterators. More...
 
template<class ForwardIterator , class T >
void fill (ForwardIterator start, ForwardIterator end, const T &value) noexcept(std::is_nothrow_copy_assignable< T >::value)
 Copy-assigns a value to all elements of a sequence specified by a pair of forward iterators. More...
 
template<class ForwardIterator , class T >
void fill_n (ForwardIterator start, std::size_t size, const T &value) noexcept(std::is_nothrow_copy_assignable< T >::value)
 Copy-assigns a value to all elements of a sequence specified by a starting iterator and the sequence size. More...
 
template<class ForwardIterator , class T >
void construct_fill (ForwardIterator start, ForwardIterator end, const T &value) noexcept(std::is_nothrow_copy_constructible< T >::value)
 Copy-constructs elements of an output sequence, specified by a pair of forward iterators, using a copy of a supplied value. More...
 
template<class ForwardIterator , class T >
void construct_fill_n (ForwardIterator start, std::size_t size, const T &value) noexcept(std::is_nothrow_copy_constructible< T >::value)
 Copy-constructs elements of an iterated output sequence of a given size using a copy of a supplied value. More...
 
template<class ElementType , std::size_t sbo_threshold, class Allocator >
void swap (sbo_vector< ElementType, sbo_threshold, Allocator > &left, sbo_vector< ElementType, sbo_threshold, Allocator > &right)
 Swaps contents of two SBO vectors. More...
 
template<class ValueTypeLeft , std::size_t sbo_threshold_left, class AllocatorLeft , class ValueTypeRight , std::size_t sbo_threshold_right, class AllocatorRight >
bool operator== (const sbo_vector< ValueTypeLeft, sbo_threshold_left, AllocatorLeft > &left, const sbo_vector< ValueTypeRight, sbo_threshold_right, AllocatorRight > &right)
 Lexicographically compares two vectors to check them against elementwise equality. More...
 
template<class ValueTypeLeft , std::size_t sbo_threshold_left, class AllocatorLeft , class ValueTypeRight , std::size_t sbo_threshold_right, class AllocatorRight >
bool operator!= (const sbo_vector< ValueTypeLeft, sbo_threshold_left, AllocatorLeft > &left, const sbo_vector< ValueTypeRight, sbo_threshold_right, AllocatorRight > &right)
 Lexicographically compares two vectors to check them against elementwise inequality. More...
 
template<class ValueTypeLeft , std::size_t sbo_threshold_left, class AllocatorLeft , class ValueTypeRight , std::size_t sbo_threshold_right, class AllocatorRight >
bool operator< (const sbo_vector< ValueTypeLeft, sbo_threshold_left, AllocatorLeft > &left, const sbo_vector< ValueTypeRight, sbo_threshold_right, AllocatorRight > &right)
 Checks whether the left vector is lexicographically less than the right vector. More...
 
template<class ValueTypeLeft , std::size_t sbo_threshold_left, class AllocatorLeft , class ValueTypeRight , std::size_t sbo_threshold_right, class AllocatorRight >
bool operator<= (const sbo_vector< ValueTypeLeft, sbo_threshold_left, AllocatorLeft > &left, const sbo_vector< ValueTypeRight, sbo_threshold_right, AllocatorRight > &right)
 Checks whether the left vector is lexicographically less than or equal to the right vector. More...
 
template<class ValueTypeLeft , std::size_t sbo_threshold_left, class AllocatorLeft , class ValueTypeRight , std::size_t sbo_threshold_right, class AllocatorRight >
bool operator> (const sbo_vector< ValueTypeLeft, sbo_threshold_left, AllocatorLeft > &left, const sbo_vector< ValueTypeRight, sbo_threshold_right, AllocatorRight > &right)
 Checks whether the left vector is lexicographically greater than the right vector. More...
 
template<class ValueTypeLeft , std::size_t sbo_threshold_left, class AllocatorLeft , class ValueTypeRight , std::size_t sbo_threshold_right, class AllocatorRight >
bool operator>= (const sbo_vector< ValueTypeLeft, sbo_threshold_left, AllocatorLeft > &left, const sbo_vector< ValueTypeRight, sbo_threshold_right, AllocatorRight > &right)
 Checks whether the left vector is lexicographically greater than or equal to the right vector. More...
 
template<class ValueTypeLeft , std::size_t sbo_threshold_left, class AllocatorLeft , class ValueTypeRight , std::size_t sbo_threshold_right, class AllocatorRight >
auto operator<=> (const sbo_vector< ValueTypeLeft, sbo_threshold_left, AllocatorLeft > &left, const sbo_vector< ValueTypeRight, sbo_threshold_right, AllocatorRight > &right)
 In C++20 performs three-way lexicographical comparison of elements of two SBO vectors. More...
 
Memory allocation mechanisms

Portable allocation functions and objects

template<class T1 , class T2 >
bool operator== (const allocator< T1 > &, const allocator< T2 > &)
 Compares two Chusov::Memory::allocator objects of different managed types. Since object of both Chusov::Memory::allocator and Chusov::Memory::secure_allocator types are stateless, two allocators are always considered to be equal. More...
 
template<class T1 , class T2 >
bool operator!= (const allocator< T1 > &, const allocator< T2 > &)
 Compares two Chusov::Memory::allocator objects of different managed types. Since object of both Chusov::Memory::allocator and Chusov::Memory::secure_allocator types are stateless, two allocators are always considered to be equal. More...
 

Detailed Description

Advanced functionality and C++ objects for working with memory.

See also
chsvmem.h