C++ Extensions (cppx) Documentation Internal Version
Main | Namespaces | Classes | NamespaceMembers | ClassMembers | Files

stdxMisc.h Classes and Functions

This is a collection of miscellaneous classes and functions which help extend the standard C++ library. It includes a generator function object, make_vector helper functions, functions to demangle C++ types, and functions to aid in dynamic type checking.

Compounds

Functions

rand Helper Functions
make_vector Helper Functions
Type Demangling Helper Functions
Dynamic Type Checking Helper Functions
Miscellaneous Functions

Detailed Documentation

Function Documentation

double genRandomProbability  
 

Produces a random value between 0 and 1 (including 0 and not including 1).

template<class T>
std::vector<T> make_vector   el1
 

Makes a vector with one element. Avoids need to construct a separate temporary vector when a user needs to pass a vector to a function.

template<class T>
std::string demangle_type  
 

This uses the gcc extensions to demangle type names. Will probably make this do nothing if user is not using gcc.

template<class T, class C>
bool isOfType const C &    obj
 

Returns true if the given object C reference is derrived from class T. This function ignores const so it doesn't matter if C or T is or is not const.

template<class Ch, class Tr>
std::basic_ostream<Ch,Tr>& nl std::basic_ostream< Ch, Tr > &    os
 

Newline io manipulator. One should use this instead of endl unless a flush of the output stream is explicitly required.

int genRandomInt int    maxInt
 

Produces a random integer from 0 to maxInt-1. This is supposedly more random than just using rand() % maxInt which can have a very regular pattern in the low order bits.

template<class T>
std::vector<T> make_vector   el1,
  el2
 

Makes a vector with two elements. Avoids need to construct a separate temporary vector when a user needs to pass a vector to a function.

template<class T>
std::vector<T> make_vector   el1,
  el2,
  el3
 

Makes a vector with three elements. Avoids need to construct a separate temporary vector when a user needs to pass a vector to a function.

template<class T>
std::vector<T> make_vector   el1,
  el2,
  el3,
  el4
 

Makes a vector with four element. Avoids need to construct a separate temporary vector when a user needs to pass a vector to a function.

template<class T>
std::string demangle_type const T &    obj
 

Same as stdx::demangle_type() except that takes an object reference as a paramter.

template<class T>
std::string demangle_type const std::type_info &    tinfo
 

Same as stdx::demangle_type() except that takes a type_info object as a paramter.

template<class T, class C>
T& verbose_dynamic_cast C &    obj
 

Performs a dynamic cast and if the cast is invalid, then the function throws a EInvalidDynamicCast exception. The key difference between this and the standard library dynamic cast is that the exception's error message is much more descriptive.

int round double    d
 

Rounds double to nearest integer

template<class In, class Out, class Pred>
Out copy_if In    first,
In    last,
Out    res,
Pred    p
 

A copy_if algoritm taken from Stroustrup's "The C++ Programming Language: 3rd Edition" Section 18.6.1. For some reason it was not included in the actual standard template library.

template<class In, class Out>
Out copy_ptr In    first,
In    last,
Out    res
 

Copies pointers to the items in the input sequence not the objects themselves. Useful for creating a "view" of a container in a separate container. For example, if you have a list of objects but want to sort them efficiently you could use:

 list<item> myList
 \\ ... fill List with strings ...
 vector<item*> ptrVec;
 copy_ptr( iseq(myList), back_inserter(ptrVec) );

 \\ Care must be take to provide a cmp function which
 \\ compares pointers to objects, or use the deref functions.
 sort( iseq(ptrVec), cmp );

template<class In, class Out, class Pred>
Out copy_ptr_if In    first,
In    last,
Out    res,
Pred    p
 

Similar to copy_ptr except also takes a predicate.

template<class In1, class In2, class BinOp>
BinOp for_each In1    first1,
In1    last1,
In2    first2,
BinOp    op
 

A two input for_each. The provided function object is called with the first argument coming from the first input sequence and the second arument coming from the second input sequence.

Generated on Mon Aug 15 21:43:09 2005 by Doxygen 1.2.13-20020210 written by Dimitri van Heesch © 1997-2002