Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

uutility.h File Reference

Utility templates. More...

#include "utypes.h"
#include <assert.h>

Namespaces

namespace  ustl
namespace  ustl::simd

Defines

#define VectorSize(v)   (sizeof(v) / sizeof(*v))
 Returns the number of elements in a static vector.
#define BitsInType(t)   (sizeof(t) * CHAR_BIT)
 Returns the number of bits in the given type.
#define BitMask(t, n)   (t(~t(0)) >> ((sizeof(t) * CHAR_BIT) - (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 NOT_SIZE_T_I_OR_L   unsigned long
 Type that is not size_t.
#define OVERLOAD_POINTER_AND_SIZE_T_V2(name, arg1type)
 Required when you want to overload size_t and a pointer.

Functions

template<typename T1, typename T2>
const T1 min (const T1 &a, const T2 &b)
 Returns the minimum of a and b.
template<typename T1, typename T2>
const T1 max (const T1 &a, const T2 &b)
 Returns the maximum of a and b.
template<typename T1, typename T2>
T1 DivRU (T1 n1, T2 n2)
 Divides n1 by n2 and rounds the result up. This is in contrast to regular division, which rounds down. Negative numbers are rounded down because they are an unusual case, supporting which would require a branch. Since this is frequently used in graphics, the speed is important.
template<typename T>
Align (T n, T grain=c_DefaultAlignment)
 Rounds n up to be divisible by grain.
template<typename T>
size_t alignof (T)
 Returns the recommended alignment for type T.
template<>
size_t alignof (bool)
template<typename T>
advance (T i, ssize_t offset)
 Offsets an iterator.
template<typename T1, typename T2>
ptrdiff_t distance (T1 i1, T2 i2)
 Returns the difference p1 - p2.
template<typename T>
absv (T v)
 Returns the absolute value of v Unlike the stdlib functions, this is inline and works with all types.
template<typename T>
sign (T v)
 Returns -1 for negative values, 1 for positive, and 0 for 0.
template<typename T1, typename T2>
size_t abs_distance (T1 i1, T2 i2)
 Returns the absolute value of the distance i1 and i2.
template<typename T>
size_t size_of_elements (size_t n, const T *)
 Returns the size of n elements of size T.
template<typename T>
void Delete (T *&p)
 Template for for_each to call delete.
template<typename T>
void DeleteVector (T *&p)
 Template for for_each to call delete.
template<typename T>
bool operator!= (const T &x, const T &y)
 Template of making != from ! and ==.
template<typename T>
bool operator> (const T &x, const T &y)
 Template of making > from <.
template<typename T>
bool operator<= (const T &x, const T &y)
 Template of making <= from < and ==.
template<typename T>
bool operator>= (const T &x, const T &y)
 Template of making >= from < and ==.
template<typename TSmall, typename TBig>
void pack_type (TSmall s, TBig &b)
 Packs s multiple times into b. Useful for loop unrolling.
bool TestAndSet (int *pm)
 Sets the contents of pm to 1 and returns true if the previous value was 0.
void reset_mmx (void)
 Call after you are done using SIMD algorithms for 64 bit tuples.

Variables

const size_t c_DefaultAlignment = sizeof(void*)
 The alignment performed by default.


Detailed Description

Utility templates.

Everything in here except min(), max(), distance(), and advance() are uSTL extensions and are absent from other STL implementations.


Define Documentation

#define NOT_SIZE_T_I_OR_L   unsigned long
 

Type that is not size_t.

Because size_t may be declared as unsigned long or unsigned int on different machines, this macro is convenient when defining overloads of size_t to use other types.

#define OVERLOAD_POINTER_AND_SIZE_T_V2 name,
arg1type   ) 
 

Value:

inline void     name (arg1type a1, short a2)                    { name (a1, size_t(a2)); }      \
    inline void name (arg1type a1, unsigned short a2)           { name (a1, size_t(a2)); }      \
    inline void name (arg1type a1, int a2)                      { name (a1, size_t(a2)); }      \
    inline void name (arg1type a1, long a2)                     { name (a1, size_t(a2)); }      \
    inline void name (arg1type a1, NOT_SIZE_T_I_OR_L a2)        { name (a1, size_t(a2)); }
Required when you want to overload size_t and a pointer.

The compiler will happily cast a number to a pointer and declare that the overload is ambiguous unless you define overloads for all possible integral types that a number may represent. This behaviour, although braindead, is in the ANSI standard, and thus not a bug. If you want to change the standard, the best solution is to disallow any implicit casts to pointer from an integral type. Ironically, such an implicit cast is already detected by gcc.


Generated on Mon Jan 17 14:35:02 2005 for uSTL by 1.3.9 Doxygen Hosted on SourceForge.net