C++テンプレート
implicit_cast
// This code taken from the Alexandrescu's "Modern C++ Design", page 32.
template <typename T>
struct Type2Type
{
typedef T OriginalType;
};
template <typename T>
inline T implicit_cast(typename Type2Type<T>::OriginalType x)
{
return x;
}
min/max
template <typename T>
inline T min(T x, T y)
{
return ((x < y) ? x : y);
}
template <typename T>
inline T max(T x, T y)
{
return ((x > y) ? x : y);
}
swap
template <typename T>
inline void swap(T& x, T& y)
{
T temp = x;
x = y;
y = temp;
}