Instigate Open Source Documentation

instigate Namespace Reference

Instigate. More...


Namespaces

namespace  generic
 This namespace provides utilities for compile time checking.
namespace  stl
 stl


Detailed Description

Instigate.

This header file provides a framework for allowing compile time dispatch based on type attributes. This is useful when writing template code. For example, when making a copy of an array of an unknown type, it helps to know if the type has a trivial copy constructor or not, to help decide if a memcpy can be used.

The class template unary_type_traits provides a series of typedefs each of which is either true_type or false_type. The argument to unary_type_traits can be any type. The typedefs within this template will attain their correct values by one of these means: 1. The general instantiation contain conservative values which work for all types. 2. Specializations may be declared to make distinctions between types. 3. Some compilers (such as the Silicon Graphics N32 and N64 compilers) will automatically provide the appropriate specializations for all types. EXAMPLE: //Copy an array of elements which have non-trivial copy constructors template %<class T%> void copy(T* source, T* destination, int n, false_type); //Copy an array of elements which have trivial copy constructors. //Use memcpy. template %<class T%> void copy(T* source, T* destination, int n, true_type); //Copy an array of any type by using the most efficient copy mechanism template %<class T%> inline void copy(T* source,T* destination,int n) { copy(source, destination, n, typename unary_type_traits<T>::has_trivial_copy_constructor()); }



© Instigate CJSC, Open Source