Namespaces | Macros | Functions | Variables
uutility.h File Reference

Utility templates. More...

#include "utypes.h"
#include "traits.h"
#include "uttraits.h"
#include "ulimits.h"
#include <assert.h>

Namespaces

 ustl
 The ustl namespace contains all ustl classes and algorithms.
 

Macros

#define VectorSize(v)   (sizeof(v) / sizeof(*v))
 Returns the number of elements in a static vector.
 
#define VectorBlock(v)   &(v)[0], VectorSize(v)
 Expands into a ptr,size expression for the given static vector; useful as link arguments.
 
#define VectorRange(v)   &(v)[0], VectorEnd(v)
 Expands into a begin,end expression for the given static vector; useful for algorithm arguments.
 
#define BitsInType(t)   (sizeof(t) * CHAR_BIT)
 Returns the number of bits in the given type.
 
#define BitMask(t, n)   (t(~t(0)) >> (BitsInType(t) - (n)))
 Returns the mask of type t with the lowest n bits set.
 
#define DebugArg(x)   x
 Argument that is used only in debug builds (as in an assert)
 
#define foreach(type, i, ctr)   for (type i = (ctr).begin(); i != (ctr).end(); ++ i)
 Shorthand for container iteration.
 
#define eachfor(type, i, ctr)   for (type i = (ctr).rbegin(); i != (ctr).rend(); ++ i)
 Shorthand for container reverse iteration.
 
#define ALL_MMX_REGS_CHANGELIST   "mm0","mm1","mm2","mm3","mm4","mm5","mm6","mm7","st","st(1)","st(2)","st(3)","st(4)","st(5)","st(6)","st(7)"
 Call after you are done using SIMD algorithms for 64 bit tuples.
 

Functions

template<typename T , size_t N>
constexpr T * ustl::VectorEnd (T(&a)[N])
 Returns the end() for a static vector.
 
template<typename T1 , typename T2 >
constexpr T1 ustl::min (const T1 &a, const T2 &b)
 Returns the minimum of a and b.
 
template<typename T1 , typename T2 >
constexpr T1 ustl::max (const T1 &a, const T2 &b)
 Returns the maximum of a and b.
 
template<typename T , size_t N>
constexpr T & ustl::VectorElement (T(&v)[N], size_t i)
 Indexes into a static array with bounds limit.
 
template<typename T >
constexpr T ustl::AlignDown (T n, size_t grain=c_DefaultAlignment)
 Rounds n up to be divisible by grain.
 
template<typename T >
constexpr T ustl::Align (T n, size_t grain=c_DefaultAlignment)
 Rounds n up to be divisible by grain.
 
template<typename T >
constexpr T * ustl::NullPointer (void)
 Returns a nullptr pointer cast to T.
 
template<typename T >
constexpr T & ustl::NullValue (void)
 Returns a non-dereferentiable value reference. This is useful for passing to stream_align_of or the like which need a value but don't need to actually use it.
 
template<typename T , typename Distance >
ustl::advance (T i, Distance offset)
 Offsets an iterator.
 
template<typename T1 , typename T2 >
constexpr ptrdiff_t ustl::distance (T1 i1, T2 i2)
 Returns the difference p1 - p2.
 
template<typename T >
constexpr T ustl::absv (T v)
 Returns the absolute value of v Unlike the stdlib functions, this is inline and works with all types.
 
template<typename T >
constexpr T ustl::sign (T v)
 Returns -1 for negative values, 1 for positive, and 0 for 0.
 
template<typename T1 , typename T2 >
constexpr size_t ustl::abs_distance (T1 i1, T2 i2)
 Returns the absolute value of the distance i1 and i2.
 
template<typename T >
constexpr size_t ustl::size_of_elements (size_t n, const T *)
 Returns the size of n elements of size T.
 
uint16_t ustl::bswap_16 (uint16_t v)
 
uint32_t ustl::bswap_32 (uint32_t v)
 
uint64_t ustl::bswap_64 (uint64_t v)
 
template<typename T >
ustl::bswap (const T &v)
 Swaps the byteorder of v.
 
template<typename T >
ustl::le_to_native (const T &v)
 
template<typename T >
ustl::be_to_native (const T &v)
 
template<typename T >
ustl::native_to_le (const T &v)
 
template<typename T >
ustl::native_to_be (const T &v)
 
template<typename T >
void ustl::Delete (T *&p)
 Deletes p and sets it to nullptr.
 
template<typename T >
void ustl::DeleteVector (T *&p)
 Deletes p as an array and sets it to nullptr.
 
template<typename T >
constexpr bool ustl::operator!= (const T &x, const T &y)
 Template of making != from ! and ==.
 
template<typename T >
constexpr bool ustl::operator> (const T &x, const T &y)
 Template of making > from <.
 
template<typename T >
constexpr bool ustl::operator<= (const T &x, const T &y)
 Template of making <= from < and ==.
 
template<typename T >
constexpr bool ustl::operator>= (const T &x, const T &y)
 Template of making >= from < and ==.
 
template<typename TSmall , typename TBig >
void ustl::pack_type (TSmall s, TBig &b)
 Packs s multiple times into b. Useful for loop unrolling.
 
template<typename T1 , typename T2 >
T1 ustl::DivRU (T1 n1, T2 n2)
 Divides n1 by n2 and rounds the result up. This is in contrast to regular division, which rounds down.
 
bool ustl::TestAndSet (int *pm)
 Sets the contents of pm to 1 and returns true if the previous value was 0.
 
uoff_t ustl::FirstBit (uint32_t v, uoff_t nbv)
 Returns the index of the first set bit in v or nbv if none.
 
uoff_t ustl::FirstBit (uint64_t v, uoff_t nbv)
 Returns the index of the first set bit in v or nbv if none.
 
uint32_t ustl::NextPow2 (uint32_t v)
 
template<typename T >
ustl::Rol (T v, size_t n)
 Bitwise rotate value left.
 
template<typename T >
ustl::Ror (T v, size_t n)
 Bitwise rotate value right.
 
template<typename DEST , typename SRC >
DEST ustl::noalias (const DEST &, SRC *s)
 This template is to be used for dereferencing a type-punned pointer without a warning. More...
 
template<typename DEST , typename SRC >
DEST ustl::noalias_cast (SRC s)
 
void ustl::simd::reset_mmx (void)
 

Variables

const size_t ustl::c_DefaultAlignment = __alignof__(void*)
 The alignment performed by default.
 

Detailed Description

Utility templates.


Generated on Mon Sep 28 2015 17:58:50 for uSTL by Doxygen 1.8.10