Index: /trunk/nv/core/common.hh
===================================================================
--- /trunk/nv/core/common.hh	(revision 373)
+++ /trunk/nv/core/common.hh	(revision 374)
@@ -137,4 +137,5 @@
 #define NV_RESTRICT_VAR __restrict
 #define NV_NOEXCEPT throw()
+#define NV_ALIGN_OF(type) __alignof(type)
 //#define NV_CONSTEXPR 
 #elif NV_COMPILER == NV_GNUC || NV_COMPILER == NV_CLANG
@@ -145,4 +146,5 @@
 #define NV_RESTRICT_VAR __restrict__
 #define NV_NOEXCEPT noexcept
+#define NV_ALIGN_OF(type) alignof(type)
 //#define NV_CONSTEXPR constexpr 
 #else
@@ -153,4 +155,5 @@
 #define NV_RESTRICT_VAR
 #define NV_NOEXCEPT 
+#define NV_ALIGN_OF
 //#define NV_CONSTEXPR 
 #endif 
@@ -171,5 +174,5 @@
 #endif
 
-#define NV_COUNT_OF(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
+#define NV_COUNT_OF(x) ((sizeof(x)/sizeof(0[x])) / ((nv::size_t)(!(sizeof(x) % sizeof(0[x])))))
 #define NV_SAFE_ARRAY( arr, idx, def ) ( index < NV_COUNT_OF(arr) ? (arr)[idx] : (def) )
 
@@ -180,4 +183,7 @@
 		class state;
 	}
+
+	using ::size_t; // typedef decltype( sizeof( int ) ) size_t;
+	using ::ptrdiff_t;
 
 	// Typedefs for fixed size types.
@@ -230,46 +236,67 @@
 	};
 
-	template <typename TYPE>
-	void construct_object( void* object )
-	{
-		new (object)TYPE;
+	template< typename T, T VALUE>
+	struct integral_constant
+	{
+		static const T value = VALUE;
+		typedef T value_type;
+		typedef integral_constant<T, VALUE> type;
+		NV_CONSTEXPR operator value_type() const { return ( value ); }
+	};
+
+	typedef integral_constant<bool, true> true_type;
+	typedef integral_constant<bool, false> false_type;
+
+	template< bool TEST, typename T = void>
+	struct enable_if {};
+
+	template< typename T >
+	struct enable_if < true, T >
+	{
+		typedef T type;
+	};
+
+	template< bool TEST, typename T1, typename T2 >
+	struct conditional
+	{
+		typedef T2 type;
+	};
+
+	template< typename T1, typename T2>
+	struct conditional < true, T1, T2 >
+	{
+		typedef T1 type;
+	};
+
+	template <typename OBJ, typename T>
+	inline size_t offset_of( T OBJ::*ptr )
+	{
+		return ( ( size_t )&( ( (OBJ*)0 )->*ptr ) );
 	}
-	template <typename TYPE>
-	void destroy_object( void* object )
-	{
-		( (TYPE*)object )->TYPE::~TYPE();
+
+	template <typename T, typename U>
+	inline T* down_cast( U* x )
+	{
+#if NV_DEBUG
+		T* p = dynamic_cast<T*>( x );
+		if ( p == 0 )
+		{
+#ifdef NV_LOG
+			NV_THROW( std::bad_cast );
+#endif
+		}
+		return p;
+#else
+		return static_cast<T*>( x );
+#endif
 	}
 
+	template <typename T, typename U>
+	T narrow_cast( const U& a )
+	{
+		return static_cast<T>( a & T( -1 ) );
+	}
+
 } // namespace nv
-
-template <typename OBJ, typename T> 
-inline size_t offset_of(T OBJ::*ptr)
-{
-	return ((size_t)&(((OBJ*)0)->*ptr));
-}
-
-template <typename T, typename U>
-inline T* down_cast(U* x)
-{
-#if NV_DEBUG
-	T* p = dynamic_cast<T*>(x);
-	if (p == 0)
-	{
-#ifdef NV_LOG
-		NV_THROW( std::bad_cast );
-#endif
-	}
-
-	return p;
-#else
-	return static_cast<T*>(x);
-#endif
-}
-
-template <typename T, typename U>
-T narrow_cast(const U& a)
-{
-	return static_cast<T>(a & T(-1) );
-}
 
 static_assert( sizeof( nv::sint8 ) == 1, "sint8 size isn't 1 bytes" );
Index: /trunk/nv/core/position.hh
===================================================================
--- /trunk/nv/core/position.hh	(revision 373)
+++ /trunk/nv/core/position.hh	(revision 374)
@@ -17,4 +17,5 @@
 #include <nv/stl/math.hh>
 #include <nv/stl/range.hh>
+#include <nv/stl/utility.hh>
 
 namespace nv
@@ -26,5 +27,5 @@
 	{
 		typedef position::value_type value_type;
-		typedef std::size_t size_type;
+		typedef size_t size_type;
 		typedef rectangle type;
 		
@@ -278,7 +279,7 @@
 		{
 			if (r.contains(*this)) return false;
-			ul = nv::max( ul, r.ul );
-			lr = nv::min( lr, r.lr );
-			ul = nv::min( ul, lr );
+			ul = glm::max( ul, r.ul );
+			lr = glm::min( lr, r.lr );
+			ul = glm::min( ul, lr );
 			return true;
 		}
@@ -293,6 +294,6 @@
 		{
 			if ( r.get_width() < get_width() || r.get_height() < get_height() ) return false;
-			(*this) += nv::min( r.ul - ul, position() );
-			(*this) -= nv::min( lr - r.lr, position() );
+			( *this ) += glm::min( r.ul - ul, position() );
+			( *this ) -= glm::min( lr - r.lr, position() );
 			return true;
 		}
@@ -303,6 +304,6 @@
 		void repair() 
 		{
-			if (ul.x > lr.x) std::swap( ul.x, lr.x );
-			if (ul.y > lr.y) std::swap( ul.y, lr.y );
+			if (ul.x > lr.x) swap( ul.x, lr.x );
+			if (ul.y > lr.y) swap( ul.y, lr.y );
 		}
 
@@ -314,6 +315,6 @@
 		void include_point( position p )
 		{
-			lr = nv::max( lr, p );
-			ul = nv::min( ul, p );
+			lr = glm::max( lr, p );
+			ul = glm::min( ul, p );
 		}
 
Index: /trunk/nv/core/types.hh
===================================================================
--- /trunk/nv/core/types.hh	(revision 373)
+++ /trunk/nv/core/types.hh	(revision 374)
@@ -110,6 +110,6 @@
 			i_type->size = sizeof( TYPE );
 
-			i_type->constructor = construct_object < TYPE > ;
-			i_type->destructor  = destroy_object < TYPE > ;
+			i_type->constructor = construct_object_raw < TYPE > ;
+			i_type->destructor  = destroy_object_raw < TYPE > ;
 			m_idx_types[typeid( TYPE )] = i_type;
 			m_type_list.push_back( i_type );
Index: /trunk/nv/formats/md5_loader.hh
===================================================================
--- /trunk/nv/formats/md5_loader.hh	(revision 373)
+++ /trunk/nv/formats/md5_loader.hh	(revision 374)
@@ -60,10 +60,4 @@
 		virtual mesh_data_pack* release_mesh_data_pack();
 		virtual size_t get_mesh_count() const { return m_meshes.size(); }
-	protected:
-		struct md5_joint_info
-		{
-			int         flags;
-			size_t      start_index;
-		};
 
 		struct md5_weight
@@ -72,4 +66,11 @@
 			float     bias;
 			glm::vec3 pos;
+		};
+
+	protected:
+		struct md5_joint_info
+		{
+			int         flags;
+			size_t      start_index;
 		};
 
Index: /trunk/nv/interface/image_data.hh
===================================================================
--- /trunk/nv/interface/image_data.hh	(revision 373)
+++ /trunk/nv/interface/image_data.hh	(revision 374)
@@ -56,5 +56,5 @@
 		void initialize( const uint8* data )
 		{
-			std::size_t bsize = static_cast<std::size_t>(m_size.x * m_size.y) * get_depth();
+			size_t bsize = static_cast<size_t>(m_size.x * m_size.y) * get_depth();
 			m_data = new uint8[ bsize ]; 
 			std::copy( data, data + bsize, m_data );
Index: /trunk/nv/interface/interpolation_template.hh
===================================================================
--- /trunk/nv/interface/interpolation_template.hh	(revision 373)
+++ /trunk/nv/interface/interpolation_template.hh	(revision 374)
@@ -19,5 +19,5 @@
 
 	template < typename KEY, animation_slot SLOT > 
-	void interpolate_slot( KEY& key, const KEY& k1, const KEY& k2, float factor, const std::true_type& )
+	void interpolate_slot( KEY& key, const KEY& k1, const KEY& k2, float factor, const true_type& )
 	{
 		key_slot_info< KEY, SLOT >::interpolate( key, k1, k2, factor );
@@ -25,5 +25,5 @@
 
 	template < typename KEY, animation_slot SLOT > 
-	void interpolate_slot( KEY&, const KEY&, const KEY&, float, const std::false_type& )
+	void interpolate_slot( KEY&, const KEY&, const KEY&, float, const false_type& )
 	{
 	}
@@ -32,8 +32,8 @@
 	void interpolate_key( KEY& key, const KEY& k1, const KEY& k2, float factor )
 	{
-		interpolate_slot< KEY, animation_slot::POSITION >( key, k1, k2, factor, std::integral_constant< bool, key_has_slot< KEY, animation_slot::POSITION >::value >() );
-		interpolate_slot< KEY, animation_slot::ROTATION >( key, k1, k2, factor, std::integral_constant< bool, key_has_slot< KEY, animation_slot::ROTATION >::value >() );
-		interpolate_slot< KEY, animation_slot::SCALE >( key, k1, k2, factor, std::integral_constant< bool, key_has_slot< KEY, animation_slot::SCALE >::value >() );
-		interpolate_slot< KEY, animation_slot::TFORM >( key, k1, k2, factor, std::integral_constant< bool, key_has_slot< KEY, animation_slot::TFORM >::value >() );
+		interpolate_slot< KEY, animation_slot::POSITION >( key, k1, k2, factor, integral_constant< bool, key_has_slot< KEY, animation_slot::POSITION >::value >() );
+		interpolate_slot< KEY, animation_slot::ROTATION >( key, k1, k2, factor, integral_constant< bool, key_has_slot< KEY, animation_slot::ROTATION >::value >() );
+		interpolate_slot< KEY, animation_slot::SCALE >( key, k1, k2, factor, integral_constant< bool, key_has_slot< KEY, animation_slot::SCALE >::value >() );
+		interpolate_slot< KEY, animation_slot::TFORM >( key, k1, k2, factor, integral_constant< bool, key_has_slot< KEY, animation_slot::TFORM >::value >() );
 	}
 
@@ -85,42 +85,42 @@
 
 		template < typename KEY >
-		mat4 extract_matrix_prs( const KEY&, const std::false_type&, const std::false_type&, const std::false_type& )
+		mat4 extract_matrix_prs( const KEY&, const false_type&, const false_type&, const false_type& )
 		{ return mat4(); }
 		template < typename KEY >
-		mat4 extract_matrix_prs( const KEY& k, const std::true_type&, const std::false_type&, const std::false_type& )
+		mat4 extract_matrix_prs( const KEY& k, const true_type&, const false_type&, const false_type& )
 		{ return extract_matrix_p_impl(k); }
 		template < typename KEY >
-		mat4 extract_matrix_prs( const KEY& k, const std::false_type&, const std::true_type&, const std::false_type& )
+		mat4 extract_matrix_prs( const KEY& k, const false_type&, const true_type&, const false_type& )
 		{ return extract_matrix_r_impl(k); }
 		template < typename KEY >
-		mat4 extract_matrix_prs( const KEY& k, const std::false_type&, const std::false_type&, const std::true_type& )
+		mat4 extract_matrix_prs( const KEY& k, const false_type&, const false_type&, const true_type& )
 		{ return extract_matrix_s_impl(k); }
 		template < typename KEY >
-		mat4 extract_matrix_prs( const KEY& k, const std::true_type&, const std::true_type&, const std::false_type& )
+		mat4 extract_matrix_prs( const KEY& k, const true_type&, const true_type&, const false_type& )
 		{ return extract_matrix_pr_impl(k); }
 		template < typename KEY >
-		mat4 extract_matrix_prs( const KEY& k, const std::false_type&, const std::true_type&, const std::true_type& )
+		mat4 extract_matrix_prs( const KEY& k, const false_type&, const true_type&, const true_type& )
 		{ return extract_matrix_rs_impl(k); }
 		template < typename KEY >
-		mat4 extract_matrix_prs( const KEY& k, const std::true_type&, const std::false_type&, const std::true_type& )
+		mat4 extract_matrix_prs( const KEY& k, const true_type&, const false_type&, const true_type& )
 		{ return extract_matrix_ps_impl(k); }
 		template < typename KEY >
-		mat4 extract_matrix_prs( const KEY& k, const std::true_type&, const std::true_type&, const std::true_type& )
+		mat4 extract_matrix_prs( const KEY& k, const true_type&, const true_type&, const true_type& )
 		{ return extract_matrix_prs_impl(k); }
 
 
 		template < typename KEY >
-		transform extract_transform_pr_impl( const KEY&, const std::false_type&, const std::false_type& ) { return transform(); }
+		transform extract_transform_pr_impl( const KEY&, const false_type&, const false_type& ) { return transform(); }
 		template < typename KEY >
-		transform extract_transform_pr_impl( const KEY& k, const std::true_type&, const std::true_type& ) { return transform( k.position, k.rotation ); }
+		transform extract_transform_pr_impl( const KEY& k, const true_type&, const true_type& ) { return transform( k.position, k.rotation ); }
 		template < typename KEY >
-		transform extract_transform_pr_impl( const KEY& k, const std::true_type&, const std::false_type& ) { return transform( k.position ); }
+		transform extract_transform_pr_impl( const KEY& k, const true_type&, const false_type& ) { return transform( k.position ); }
 		template < typename KEY >
-		transform extract_transform_pr_impl( const KEY& k, const std::false_type&, const std::true_type& ) { return transform( k.rotation ); }
+		transform extract_transform_pr_impl( const KEY& k, const false_type&, const true_type& ) { return transform( k.rotation ); }
 
 
 
 		template < typename KEY >
-		mat4 extract_matrix_impl( const KEY& k, const std::true_type& )
+		mat4 extract_matrix_impl( const KEY& k, const true_type& )
 		{
 			static_assert( key_has_slot< KEY, animation_slot::POSITION >::value == false, "key!");
@@ -131,16 +131,16 @@
 
 		template < typename KEY >
-		mat4 extract_matrix_impl( const KEY& k, const std::false_type& )
+		mat4 extract_matrix_impl( const KEY& k, const false_type& )
 		{
 			static_assert( key_has_slot< KEY, animation_slot::TFORM >::value == false, "key!");
 			return extract_matrix_prs( k,
-				std::integral_constant< bool, key_has_slot< KEY, animation_slot::POSITION >::value >(),
-				std::integral_constant< bool, key_has_slot< KEY, animation_slot::ROTATION >::value >(),
-				std::integral_constant< bool, key_has_slot< KEY, animation_slot::SCALE >::value >()
+				integral_constant< bool, key_has_slot< KEY, animation_slot::POSITION >::value >(),
+				integral_constant< bool, key_has_slot< KEY, animation_slot::ROTATION >::value >(),
+				integral_constant< bool, key_has_slot< KEY, animation_slot::SCALE >::value >()
 				);
 		}
 
 		template < typename KEY >
-		transform extract_transform_impl( const KEY& k, const std::true_type& )
+		transform extract_transform_impl( const KEY& k, const true_type& )
 		{
 			static_assert( key_has_slot< KEY, animation_slot::POSITION >::value == false, "key!");
@@ -151,11 +151,11 @@
 
 		template < typename KEY >
-		transform extract_transform_impl( const KEY& k, const std::false_type& )
+		transform extract_transform_impl( const KEY& k, const false_type& )
 		{
 			static_assert( key_has_slot< KEY, animation_slot::TFORM >::value == false, "key!");
 			static_assert( key_has_slot< KEY, animation_slot::SCALE >::value == false, "key!");
 			return extract_transform_pr_impl( k, 
-				std::integral_constant< bool, key_has_slot< KEY, animation_slot::POSITION >::value >(),
-				std::integral_constant< bool, key_has_slot< KEY, animation_slot::ROTATION >::value >() 
+				integral_constant< bool, key_has_slot< KEY, animation_slot::POSITION >::value >(),
+				integral_constant< bool, key_has_slot< KEY, animation_slot::ROTATION >::value >() 
 				);
 		}
@@ -165,5 +165,5 @@
 	mat4 extract_matrix( const KEY& k )
 	{
-		return detail::extract_matrix_impl( k, std::integral_constant< bool, key_has_slot< KEY, animation_slot::TFORM >::value >() );
+		return detail::extract_matrix_impl( k, integral_constant< bool, key_has_slot< KEY, animation_slot::TFORM >::value >() );
 	}
 
@@ -171,5 +171,5 @@
 	transform extract_transform( const KEY& k )
 	{
-		return detail::extract_transform_impl( k, std::integral_constant< bool, key_has_slot< KEY, animation_slot::TFORM >::value >() );
+		return detail::extract_transform_impl( k, integral_constant< bool, key_has_slot< KEY, animation_slot::TFORM >::value >() );
 	}
 
Index: /trunk/nv/lib/curses.hh
===================================================================
--- /trunk/nv/lib/curses.hh	(revision 373)
+++ /trunk/nv/lib/curses.hh	(revision 374)
@@ -29,7 +29,7 @@
 #endif
 
-#include <stdarg.h>
-#include <stddef.h>
+#ifdef CURSES_PDC_WIDE
 #include <wchar.h>
+#endif
 
 #include <nv/lib/detail/curses_types.inc>
@@ -41,6 +41,7 @@
 #endif
 
+#define FILE void
 #include <nv/lib/detail/curses_functions.inc>
-
+#undef FILE
 #undef NV_CURSES_FUN
 }
Index: /trunk/nv/lua/lua_glm.hh
===================================================================
--- /trunk/nv/lua/lua_glm.hh	(revision 373)
+++ /trunk/nv/lua/lua_glm.hh	(revision 374)
@@ -7,5 +7,4 @@
 #define NV_LUA_GLM_HH
 
-#include <new>
 #include <nv/core/common.hh>
 #include <nv/stl/math.hh>
Index: /trunk/nv/stl/algorithm.hh
===================================================================
--- /trunk/nv/stl/algorithm.hh	(revision 374)
+++ /trunk/nv/stl/algorithm.hh	(revision 374)
@@ -0,0 +1,251 @@
+// Copyright (C) 2015 ChaosForge Ltd
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+/**
+* @file algorithm.hh
+* @author Kornel Kisielewicz epyon@chaosforge.org
+* @brief STL algorithm library
+*/
+// TODO: implement fill_default!
+
+#ifndef NV_STL_ALGORITHM_HH
+#define NV_STL_ALGORITHM_HH
+
+#include <nv/core/common.hh>
+#include <nv/stl/utility.hh>
+#include <nv/stl/iterator.hh>
+
+namespace nv
+{
+
+	template < typename InputIterator, typename EqualityComparable >
+	inline typename iterator_traits<InputIterator>::difference_type 
+	count( InputIterator first, InputIterator last, const EqualityComparable& value )
+	{
+		typename iterator_traits<InputIterator>::difference_type result = 0;
+		while ( first != last )
+		{
+			if ( *first == value ) ++result;
+			++first;
+		}
+		return result;
+	}
+
+	template < typename InputIterator, typename EqualityComparable >
+	inline InputIterator find( InputIterator first, InputIterator last, const EqualityComparable& val )
+	{
+		while ( first != last )
+		{
+			if ( *first == val ) return first;
+			++first;
+		}
+		return last;
+	}
+
+	template < typename InputIterator, typename UnaryPredicate >
+	inline InputIterator find_if( InputIterator first, InputIterator last, UnaryPredicate find_op )
+	{
+		for ( ; first != last; ++first )
+			if ( find_op( *first ) )
+				break;
+		return first;
+	}
+
+	template < typename InputIterator, typename ForwardIterator >
+	inline InputIterator find_first_of( InputIterator first1, InputIterator last1, ForwardIterator first2, ForwardIterator last2 )
+	{
+		for ( ; first1 != last1; ++first1 )
+			for ( ForwardIterator it = first2; it != last2; ++it )
+				if ( *first1 == *it )
+					break;
+		return ( first1 );
+	}
+
+	template < typename InputIterator, typename ForwardIterator, typename BinaryPredicate >
+	inline InputIterator find_first_of( InputIterator first1, InputIterator last1, ForwardIterator first2, ForwardIterator last2, BinaryPredicate comp_op )
+	{
+		for ( ; first1 != last1; ++first1 )
+			for ( ForwardIterator it = first2; it != last2; ++it )
+				if ( comp_op( *first1, *it ) )
+					break;
+		return ( first1 );
+	}
+
+	template < typename ForwardIterator1, typename ForwardIterator2, typename BinaryPredicate >
+	inline ForwardIterator1 search( ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate comp_op )
+	{
+		if ( first2 == last2 ) return first1;
+		while ( first1 != last1 )
+		{
+			ForwardIterator1 it1 = first1;
+			ForwardIterator2 it2 = first2;
+			while ( comp_op( *it1, *it2 ) )
+			{
+				++it1; ++it2;
+				if ( it2 == last2 ) return first1;
+				if ( it1 == last1 ) return last1;
+			}
+			++first1;
+		}
+		return last1;
+	}
+
+	template < typename ForwardIterator1, typename ForwardIterator2 >
+	inline ForwardIterator1 search( ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2 )
+	{
+		if ( first2 == last2 ) return first1; 
+		while ( first1 != last1 )
+		{
+			ForwardIterator1 it1 = first1;
+			ForwardIterator2 it2 = first2;
+			while ( *it1 == *it2 )
+			{
+				++it1; ++it2;
+				if ( it2 == last2 ) return first1;
+				if ( it1 == last1 ) return last1;
+			}
+			++first1;
+		}
+		return last1;
+	}
+
+	template < typename InputIterator, typename OutputIterator, typename UnaryOperator >
+	inline OutputIterator transform_seq( InputIterator first1, InputIterator last1, OutputIterator result, UnaryOperator op )
+	{
+		for ( ; first1 != last1; ++result, ++first1 )
+			*result = op( *first1 );
+		return result;
+	}
+
+	template < typename InputIterator1, typename InputIterator2, typename OutputIterator, typename BinaryOperator >
+	inline OutputIterator transform_seq( InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputIterator result, BinaryOperator binary_op )
+	{
+		for ( ; first1 != last1; ++result, ++first1, ++first2 )
+			*result = binary_op( *first1, *first2 );
+		return result;
+	}
+
+	template < typename ForwardIterator, typename UnaryPredicate >
+	inline ForwardIterator remove_if( ForwardIterator first, ForwardIterator last, UnaryPredicate pred )
+	{
+		ForwardIterator result = first;
+		while ( first != last )
+		{
+			if ( !pred( *first ) )
+			{
+				*result = move( *first );
+				++result;
+			}
+			++first;
+		}
+		return result;
+	}
+
+	template < typename Iterator >
+	inline void iter_swap( Iterator a, Iterator b )
+	{
+		swap( *a, *b );
+	}
+
+	template <typename BidirectionalIterator>
+	inline void reverse( BidirectionalIterator first, BidirectionalIterator last )
+	{
+		for ( ; distance( first, --last ) > 0; ++first )
+			iter_swap( first, last );
+	}
+
+	template < typename ForwardIterator >
+	ForwardIterator rotate( ForwardIterator first, ForwardIterator middle, ForwardIterator last )
+	{
+		if ( first == middle || middle == last )
+			return first;
+		reverse( first, middle );
+		reverse( middle, last );
+		for ( ; first != middle && middle != last; ++first )
+			iter_swap( first, --last );
+		reverse( first, ( first == middle ? last : middle ) );
+		return first;
+	}
+
+	// TODO: specialize for rotate on pointers!
+	//template <typename T>
+	//inline T* rotate( T* first, T* middle, T* last );
+
+	template < typename RandomAccessIterator, typename Compare >
+	void stable_sort( RandomAccessIterator first, RandomAccessIterator last, Compare comp )
+	{
+		for ( RandomAccessIterator j, i = first; ++i < last; )
+		{
+			for ( j = i; j-- > first && comp( *i, *j ); );
+			if ( ++j != i ) rotate( j, i, i + 1 );
+		}
+	}
+
+	namespace detail
+	{
+		template < typename ForwardIterator, typename T >
+		void fill_impl( ForwardIterator first, ForwardIterator last, const T& value, false_type )
+		{
+			for (; first != last; ++first )
+				*first = value;
+		}
+
+		template < typename ForwardIterator, typename T >
+		void fill_impl( ForwardIterator first, ForwardIterator last, const T& value, true_type )
+		{
+			memset( first, value, last - first );
+		}
+
+		template < typename ForwardIterator, typename T >
+		ForwardIterator fill_n_impl( ForwardIterator first, size_t count, const T& value, false_type )
+		{
+			for ( ; count-- > 0; ++first ) *first = value;
+			return first;
+		}
+
+		template < typename ForwardIterator, typename T >
+		ForwardIterator fill_n_impl( ForwardIterator first, size_t count, const T& value, true_type )
+		{
+			return ForwardIterator( memset( first, value, count ) + count );
+		}
+	}
+
+	// TODO: fill_default special case!
+	template < typename ForwardIterator, typename T > 
+	inline void fill( ForwardIterator first, ForwardIterator last, const T& value )
+	{
+		detail::fill_impl( first, last, value,
+			integral_constant< bool, sizeof( T ) == 1 && has_trivial_assign<T>::value >() );
+	}
+
+	template < typename ForwardIterator, typename T >
+	inline ForwardIterator fill_n( ForwardIterator first, size_t count, const T& value )
+	{
+		return detail::fill_n_impl( first, count, value,
+			integral_constant< bool, sizeof( T ) == 1 && has_trivial_assign<T>::value >() );
+	}
+
+	template < typename ForwardIterator >
+	inline void fill_default( ForwardIterator first, ForwardIterator last )
+	{
+		// TODO: implement
+		typedef typename iterator_traits< ForwardIterator >::value_type value_type;
+		detail::fill_impl( first, last, value_type(),
+			integral_constant< bool, sizeof( value_type ) == 1 && has_trivial_assign<value_type>::value >() );
+	}
+
+	template < typename ForwardIterator >
+	inline ForwardIterator fill_default_n( ForwardIterator first, size_t count )
+	{
+		// TODO: implement
+		typedef typename iterator_traits< ForwardIterator >::value_type value_type;
+		return detail::fill_n_impl( first, count, value_type(),
+			integral_constant< bool, sizeof( value_type ) == 1 && has_trivial_assign<value_type>::value >() );
+	}
+
+}
+
+#endif // NV_STL_ALGORITHM_HH
Index: /trunk/nv/stl/allocator.hh
===================================================================
--- /trunk/nv/stl/allocator.hh	(revision 373)
+++ /trunk/nv/stl/allocator.hh	(revision 374)
@@ -20,5 +20,5 @@
 
 #include <nv/core/common.hh>
-#include <nv/core/type_traits.hh>
+#include <nv/stl/type_traits.hh>
 
 namespace nv
@@ -41,5 +41,5 @@
 		T *create( Args&&... args ) 
 		{
-			return new ( allocate( sizeof( T ), alignof( T ) ) ) T( std::forward<Args>( args )... );
+			return new ( allocate( sizeof( T ), alignof( T ) ) ) T( forward<Args>( args )... );
 		}
 
Index: /trunk/nv/stl/any.hh
===================================================================
--- /trunk/nv/stl/any.hh	(revision 373)
+++ /trunk/nv/stl/any.hh	(revision 374)
@@ -17,5 +17,7 @@
 
 #include <nv/core/common.hh>
-#include <nv/core/type_traits.hh>
+#include <nv/stl/type_traits.hh>
+#include <nv/stl/type_info.hh>
+#include <nv/stl/utility.hh>
 
 namespace nv
@@ -42,5 +44,5 @@
 		template< typename T >
 		any( T&& value )
-			: m_content( new holder<T>( std::forward<T>(value) ) )
+			: m_content( new holder<T>( forward<T>(value) ) )
 		{}
 
@@ -52,5 +54,5 @@
 		any& swap( any& rhs )
 		{
-			std::swap( m_content, rhs.m_content );
+			nv::swap( m_content, rhs.m_content );
 			return *this;
 		}
@@ -71,5 +73,5 @@
 		any& operator= ( T&& rhs )
 		{
-			any( std::forward<T>(rhs) ).swap(*this);
+			any( forward<T>(rhs) ).swap(*this);
 			return *this;
 		}
@@ -123,5 +125,5 @@
 			{
 			}
-			holder( T&& value ) : held(std::forward<T>(value))
+			holder( T&& value ) : held(forward<T>(value))
 			{
 			}
Index: /trunk/nv/stl/array.hh
===================================================================
--- /trunk/nv/stl/array.hh	(revision 373)
+++ /trunk/nv/stl/array.hh	(revision 374)
@@ -16,4 +16,6 @@
 #include <nv/core/common.hh>
 #include <nv/stl/memory.hh>
+#include <nv/stl/iterator.hh>
+#include <nv/stl/utility.hh>
 #include <vector>
 #include <algorithm>
@@ -23,36 +25,36 @@
 {
 	using std::vector;
-	using std::array;
-
-	template< class T, std::size_t N >
-	class static_array : public detail::data_base< T, false, N >
+
+	template< typename T, size_t N >
+	class array : public detail::pointer_iterators < array< T, N >, T, false >
 	{
 	public:
-		typedef T              value_type;
-		typedef T*             iterator;
-		typedef const T*       const_iterator;
-		typedef T&             reference;
-		typedef const T&       const_reference;
-		typedef std::size_t    size_type;
-		typedef std::ptrdiff_t difference_type;
-
-		typedef std::reverse_iterator<iterator>       reverse_iterator;
-		typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
-
-// 		iterator        begin()        { return m_data; }
-// 		const_iterator  begin()  const { return m_data; }
-// 		const_iterator  cbegin() const { return m_data; }
-// 
-// 		iterator        end()        { return m_data+N; }
-// 		const_iterator  end()  const { return m_data+N; }
-// 		const_iterator  cend() const { return m_data+N; }
-// 
-// 		reverse_iterator rbegin()              { return reverse_iterator( end() ); }
-// 		const_reverse_iterator rbegin() const  { return const_reverse_iterator( end() ); }
-// 		const_reverse_iterator crbegin() const { return const_reverse_iterator( end() ); }
-// 
-// 		reverse_iterator rend()                { return reverse_iterator( begin() ); }
-// 		const_reverse_iterator rend() const    { return const_reverse_iterator( begin() ); }
-// 		const_reverse_iterator crend() const   { return const_reverse_iterator( begin() ); }
+		typedef T         value_type;
+		typedef size_t    size_type;
+		typedef ptrdiff_t difference_type;
+		typedef T*        pointer;
+		typedef const T*  const_pointer;
+		typedef T*        iterator;
+		typedef const T*  const_iterator;
+		typedef T&        reference;
+		typedef const T&  const_reference;
+		typedef nv::reverse_iterator<iterator>       reverse_iterator;
+		typedef nv::reverse_iterator<const_iterator> const_reverse_iterator;
+
+		static const size_type SIZE = N;
+		static const size_type ELEMENT_SIZE = sizeof( value_type );
+
+		inline const_pointer data() const { return m_data; }
+		inline pointer data() { return m_data; }
+		inline size_type size() const { return SIZE; }
+		inline bool empty() const { return false; }
+		inline size_type   raw_size() const { return SIZE * sizeof( T ); }
+		inline const char* raw_data() const { return (const char*)m_data; }
+		inline char*       raw_data() { return (char*)m_data; }
+
+		inline reference       front() { NV_ASSERT( !empty(), "front() called on empty data!" );  return m_data[0]; }
+		inline const_reference front() const { NV_ASSERT( !empty(), "front() called on empty data!" ); return m_data[0]; }
+		inline reference       back() { NV_ASSERT( !empty(), "front() called on empty data!" ); return m_data[SIZE - 1]; }
+		inline const_reference back() const { NV_ASSERT( !empty(), "front() called on empty data!" ); return m_data[SIZE - 1]; }
 
 		reference operator[]( size_type i ) 
@@ -68,24 +70,131 @@
 		}
 
-// 		reference       front()       { return m_data[0]; }
-// 		const_reference front() const { return m_data[0]; }
-// 		reference       back()        { return m_data[N-1]; }
-// 		const_reference back() const  { return m_data[N-1]; }
-// 
-// 		static size_type size()     { return N; }
-// 		static bool      empty()    { return false; }
-// 		static size_type max_size() { return N; }
-// 
-// 		const value_type* data() const { return m_data; }
-// 		value_type*       data()       { return m_data; }
-// 
-// 		size_type   raw_size() const { return N * ELEMENT_SIZE; }
-// 		const char* raw_data() const { return (const char*)m_data; }
-// 		char*       raw_data()       { return (char*)m_data; }
-
-		void assign( const value_type& value ) { std::fill_n( this->begin(), this->size(), value ); }
-
-		static const size_type SIZE = N;
-		static const size_type ELEMENT_SIZE = sizeof(T);
+		reference at( size_type i )
+		{
+			NV_ASSERT( i < N, "Out of range" );
+			return this->m_data[i];
+		}
+
+		const_reference at( size_type i ) const
+		{
+			NV_ASSERT( i < N, "Out of range" );
+			return this->m_data[i];
+		}
+
+		void swap( array<value_type, N>& y )
+		{
+			for ( size_type i = 0; i < N; ++i )
+				nv::swap( m_data[i], y.m_data[i] );
+		}
+
+		void assign( const value_type& value ) { fill( value ); }
+
+		void fill( const value_type& value )
+		{
+			std::fill_n( this->begin(), this->size(), value );
+		}
+
+	private:
+		value_type m_data[SIZE];
+	};
+
+	template< typename T, size_t N >
+	inline void swap( array<T, N>& lhs, array<T, N>& rhs )
+	{
+		lhs.swap( rhs );
+	}
+
+// 	template < typename T, typename ContainerAllocator >
+// 	class vector_base
+// 	{
+// 	public:
+// 		typedef T         value_type;
+// 		typedef size_t    size_type;
+// 		typedef ptrdiff_t difference_type;
+// 		typedef T*        pointer;
+// 		typedef const T*  const_pointer;
+// 		typedef T*        iterator;
+// 		typedef const T*  const_iterator;
+// 		typedef T&        reference;
+// 		typedef const T&  const_reference;
+// 
+// 	protected:
+// 		ContainerAllocator m_storage;
+// 	};
+
+// 	template< typename T, size_t N >
+// 	class static_vector : public detail::pointer_iterators < static_vector< T, N >, T, false >
+// 	{
+// 	public:
+// 		typedef T         value_type;
+// 		typedef size_t    size_type;
+// 		typedef ptrdiff_t difference_type;
+// 		typedef T*        pointer;
+// 		typedef const T*  const_pointer;
+// 		typedef T*        iterator;
+// 		typedef const T*  const_iterator;
+// 		typedef T&        reference;
+// 		typedef const T&  const_reference;
+// 		typedef nv::reverse_iterator<iterator>       reverse_iterator;
+// 		typedef nv::reverse_iterator<const_iterator> const_reverse_iterator;
+// 
+// 		static_vector() : m_size(0) {}
+// 
+// 		inline const_pointer data() const { return m_data; }
+// 		inline pointer data() { return m_data; }
+// 		inline size_type size() const { return m_size; }
+// 		inline bool empty() const { return !m_size; }
+// 		inline size_type   raw_size() const { return N * sizeof( T ); }
+// 		inline const char* raw_data() const { return (const char*)m_data; }
+// 		inline char*       raw_data() { return (char*)m_data; }
+// 
+// 		inline reference       front() { NV_ASSERT( !empty(), "front() called on empty data!" );  return m_data[0]; }
+// 		inline const_reference front() const { NV_ASSERT( !empty(), "front() called on empty data!" ); return m_data[0]; }
+// 		inline reference       back() { NV_ASSERT( !empty(), "front() called on empty data!" ); return m_data[m_size - 1]; }
+// 		inline const_reference back() const { NV_ASSERT( !empty(), "front() called on empty data!" ); return m_data[m_size - 1]; }
+// 	protected:
+// 		value_type m_data[N];
+// 		size_type  m_size;
+// 	};
+
+	template < typename T, typename ContainerAllocator >
+	class array_base : public detail:: pointer_iterators < array_base< T, ContainerAllocator >, T, false >
+	{
+	public:
+		typedef T         value_type;
+		typedef size_t    size_type;
+		typedef ptrdiff_t difference_type;
+		typedef T*        pointer;
+		typedef const T*  const_pointer;
+		typedef T*        iterator;
+		typedef const T*  const_iterator;
+		typedef T&        reference;
+		typedef const T&  const_reference;
+		typedef nv::reverse_iterator<iterator>       reverse_iterator;
+		typedef nv::reverse_iterator<const_iterator> const_reverse_iterator;
+
+		inline array_base() : m_storage() {}
+		inline array_base( pointer a_data, size_t a_size )
+		{
+
+		}
+		inline const_pointer data() const { return m_storage.data(); }
+		inline pointer data() { return m_storage.data(); }
+		inline size_t size() const { return m_storage.size(); }
+		inline bool empty() const { return m_storage.size() != 0; }
+		inline size_type   raw_size() const { return sizeof( T ) * m_storage.size(); }
+		inline const char* raw_data() const { return (const char*)m_storage.data(); }
+		inline char*       raw_data() { return (char*)m_storage.data(); }
+
+		inline reference       front() { NV_ASSERT( !empty(), "front() called on empty data!" );  return m_storage.data()[0]; }
+		inline const_reference front() const { NV_ASSERT( !empty(), "front() called on empty data!" ); return m_storage.data()[0]; }
+		inline reference       back() { NV_ASSERT( !empty(), "front() called on empty data!" ); return m_storage.data()[size() - 1]; }
+		inline const_reference back() const { NV_ASSERT( !empty(), "front() called on empty data!" ); return m_storage.data()[size() - 1]; }
+	protected:
+		void push_values( size_type n, const value_type& value )
+		{
+
+		}
+		ContainerAllocator m_storage;
 	};
 
@@ -94,14 +203,14 @@
 	{
 	public:
-		typedef T              value_type;
-		typedef T*             iterator;
-		typedef const T*       const_iterator;
-		typedef T&             reference;
-		typedef const T&       const_reference;
-		typedef std::size_t    size_type;
-		typedef std::ptrdiff_t difference_type;
-
-		typedef std::reverse_iterator<iterator>       reverse_iterator;
-		typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
+		typedef T         value_type;
+		typedef T*        iterator;
+		typedef const T*  const_iterator;
+		typedef T&        reference;
+		typedef const T&  const_reference;
+		typedef size_t    size_type;
+		typedef ptrdiff_t difference_type;
+
+		typedef nv::reverse_iterator<iterator>       reverse_iterator;
+		typedef nv::reverse_iterator<const_iterator> const_reverse_iterator;
 
 		dynamic_array() : detail::data_base< T, false, 0 >() {}
@@ -166,5 +275,5 @@
 // 		size_type        size() const     { return m_size; }
 // 		bool             empty() const    { return m_size == 0; }
-// 		static size_type max_size()       { return std::numeric_limits< size_type >::max(); }
+// 		static size_type max_size()       { return numeric_limits< size_type >::max(); }
 // 		const value_type* data() const { return m_data; }
 // 		value_type*       data()       { return m_data; }
@@ -191,4 +300,6 @@
 	};
 
+
+
 }
 
Index: /trunk/nv/stl/flags.hh
===================================================================
--- /trunk/nv/stl/flags.hh	(revision 373)
+++ /trunk/nv/stl/flags.hh	(revision 374)
@@ -63,12 +63,12 @@
 			friend class flags<SIZE,T>;
 		public:
-			typedef T              index_type;
-			typedef T              value_type;
-			typedef T*             iterator;
-			typedef const T*       const_iterator;
-			typedef T&             reference;
-			typedef const T&       const_reference;
-			typedef std::size_t    size_type;
-			typedef std::ptrdiff_t difference_type;
+			typedef T         index_type;
+			typedef T         value_type;
+			typedef T*        iterator;
+			typedef const T*  const_iterator;
+			typedef T&        reference;
+			typedef const T&  const_reference;
+			typedef size_t    size_type;
+			typedef ptrdiff_t difference_type;
 
 			T operator* () const { return m_index; }
Index: /trunk/nv/stl/iterator.hh
===================================================================
--- /trunk/nv/stl/iterator.hh	(revision 374)
+++ /trunk/nv/stl/iterator.hh	(revision 374)
@@ -0,0 +1,217 @@
+// Copyright (C) 2015 ChaosForge Ltd
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+/**
+* @file iterator.hh
+* @author Kornel Kisielewicz epyon@chaosforge.org
+* @brief STL iterator library
+*/
+
+#ifndef NV_STL_ITERATOR_HH
+#define NV_STL_ITERATOR_HH
+
+#include <nv/core/common.hh>
+
+namespace nv
+{
+	struct input_iterator_tag {};
+	struct output_iterator_tag {};
+	struct forward_iterator_tag : input_iterator_tag {};
+	struct bidirectional_iterator_tag : forward_iterator_tag {};
+	struct random_access_iterator_tag : bidirectional_iterator_tag {};
+	struct block_access_iterator_tag : random_access_iterator_tag{};
+
+	template < typename Category, typename T, typename Distance = ptrdiff_t,
+		typename Pointer = T*, typename Reference = T& >
+	struct iterator
+	{
+		typedef T         value_type;
+		typedef Distance  difference_type;
+		typedef Pointer   pointer;
+		typedef Reference reference;
+		typedef Category  iterator_category;
+	};
+
+	template < typename Iterator >
+	struct iterator_traits
+	{
+		typedef typename Iterator::iterator_category iterator_category;
+		typedef typename Iterator::value_type        value_type;
+		typedef typename Iterator::difference_type   difference_type;
+		typedef typename Iterator::pointer           pointer;
+		typedef typename Iterator::reference         reference;
+	};
+
+	template < typename T >
+	struct iterator_traits < T* >
+	{
+		typedef block_access_iterator_tag iterator_category;
+		typedef T                         value_type;
+		typedef ptrdiff_t                 difference_type;
+		typedef T*                        pointer;
+		typedef T&                        reference;
+	};
+
+	template < typename T >
+	struct iterator_traits < const T* >
+	{
+		typedef block_access_iterator_tag iterator_category;
+		typedef T                         value_type;
+		typedef ptrdiff_t                 difference_type;
+		typedef const T*                  pointer;
+		typedef const T&                  reference;
+	};
+
+	template <>
+	struct iterator_traits < void* >
+	{
+		typedef block_access_iterator_tag iterator_category;
+		typedef uint8                     value_type;
+		typedef ptrdiff_t                 difference_type;
+		typedef void*                     pointer;
+		typedef uint8&                    reference;
+	};
+
+	template <>
+	struct iterator_traits < const void* >
+	{
+		typedef block_access_iterator_tag iterator_category;
+		typedef uint8                     value_type;
+		typedef ptrdiff_t                 difference_type;
+		typedef const void*               pointer;
+		typedef const uint8&              reference;
+	};
+
+	template <typename Iterator>
+	class reverse_iterator : public iterator 
+	  < typename iterator_traits<Iterator>::iterator_category,
+		typename iterator_traits<Iterator>::value_type,
+		typename iterator_traits<Iterator>::difference_type,
+		typename iterator_traits<Iterator>::pointer,
+		typename iterator_traits<Iterator>::reference >
+	{
+	public:
+		typedef Iterator                                              iterator_type;
+		typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
+		typedef typename iterator_traits<Iterator>::value_type        value_type;
+		typedef typename iterator_traits<Iterator>::pointer           pointer;
+		typedef typename iterator_traits<Iterator>::reference         reference;
+		typedef typename iterator_traits<Iterator>::difference_type   difference_type;
+
+	public:
+		reverse_iterator() : m_base() {}
+		explicit reverse_iterator( iterator_type i ) : m_base( i ) {}
+
+		template <typename U>
+		reverse_iterator( const reverse_iterator<U>& ri ) : m_base( ri.base() ) {}
+
+		iterator_type base() const { return m_base; }
+		reference operator*( ) const { iterator_type i( m_base ); return *--i; }
+		pointer operator->( ) const { return &( operator*( ) ); }
+		reverse_iterator& operator++( ) { --m_base; return *this; }
+		reverse_iterator operator++( int ) { reverse_iterator ri( *this ); --m_base; return ri; }
+		reverse_iterator& operator--( ) { ++m_base; return *this; }
+		reverse_iterator operator--( int ) { reverse_iterator ri( *this ); ++m_base; return ri; }
+		reverse_iterator operator+( difference_type n ) const { return reverse_iterator( m_base - n ); }
+		reverse_iterator& operator+=( difference_type n ) { m_base -= n; return *this; }
+		reverse_iterator operator-( difference_type n ) const { return reverse_iterator( m_base + n ); }
+		reverse_iterator& operator-=( difference_type n ) { m_base += n; return *this; }
+		reference operator[]( difference_type n ) const { return m_base[-n - 1]; }
+	protected:
+		iterator_type m_base;
+	};
+
+	template < typename Iterator1, typename Iterator2 >
+	inline bool operator==( const reverse_iterator< Iterator1 >& lhs, const reverse_iterator< Iterator2 >& rhs )
+	{ return lhs.base() == rhs.base(); }
+	template < typename Iterator1, typename Iterator2 >
+	inline bool operator!=( const reverse_iterator< Iterator1 >& lhs, const reverse_iterator< Iterator2 >& rhs )
+	{ return lhs.base() != rhs.base(); }
+	template < typename Iterator1, typename Iterator2 >
+	inline bool operator<( const reverse_iterator< Iterator1 >& lhs, const reverse_iterator< Iterator2 >& rhs )
+	{ return lhs.base() > rhs.base(); }
+	template < typename Iterator1, typename Iterator2 >
+	inline bool operator>( const reverse_iterator< Iterator1>& lhs, const reverse_iterator< Iterator2 >& rhs )
+	{ return lhs.base() < rhs.base(); }
+	template < typename Iterator1, typename Iterator2 >
+	inline bool operator<=( const reverse_iterator< Iterator1 >& lhs, const reverse_iterator<Iterator2 >& rhs )
+	{ return lhs.base() >= rhs.base(); }
+	template < typename Iterator1, typename Iterator2 >
+	inline bool operator>=( const reverse_iterator< Iterator1 >& lhs, const reverse_iterator<Iterator2 >& rhs )
+	{ return lhs.base() <= rhs.base(); }
+	template < typename Iterator1, typename Iterator2 >
+	inline typename reverse_iterator<Iterator1>::difference_type operator-( const reverse_iterator<Iterator1>& lhs, const reverse_iterator<Iterator2>& rhs )
+	{ return lhs.base() - rhs.base(); }
+	template < typename Iterator > inline reverse_iterator<Iterator> operator+( typename reverse_iterator<Iterator>::difference_type n, const reverse_iterator<Iterator>& iter )
+	{ return reverse_iterator<Iterator>( iter.base() - n ); }
+
+	namespace detail
+	{
+		template < typename InputIterator >
+		inline typename iterator_traits< InputIterator >::difference_type
+		distance_impl( InputIterator first, InputIterator last, input_iterator_tag )
+		{
+			typename iterator_traits< InputIterator >::difference_type n = 0;
+			while ( first != last )
+			{
+				++first;
+				++n;
+			}
+			return n;
+		}
+
+		template < typename RandomAccessIterator >
+		inline typename iterator_traits< RandomAccessIterator >::difference_type
+		distance_impl( RandomAccessIterator first, RandomAccessIterator last, random_access_iterator_tag )
+		{
+			return last - first;
+		}
+
+		template < typename InputIterator, typename Distance >
+		inline void advance_impl( InputIterator& iter, Distance n, input_iterator_tag )
+		{
+			while ( n-- ) ++iter;
+		}
+
+		template < typename BidirectionalIterator, typename Distance >
+		inline void advance_impl( BidirectionalIterator& iter, Distance n, bidirectional_iterator_tag )
+		{
+			if ( n > 0 )
+			{
+				while ( n-- ) ++iter;
+			}
+			else
+			{
+				while ( n++ ) --iter;
+			}
+		}
+
+		template < typename RandomAccessIterator, typename Distance >
+		inline void advance_impl( RandomAccessIterator& iter, Distance n, random_access_iterator_tag )
+		{
+			iter += n;
+		}
+
+	}
+
+	template < typename InputIterator >
+	inline typename iterator_traits< InputIterator >::difference_type
+	distance( InputIterator first, InputIterator last )
+	{
+		typedef typename iterator_traits< InputIterator >::iterator_category category;
+		return detail::distance_impl( first, last, category() );
+	}
+
+	template < typename InputIterator, typename Distance >
+	inline void advance( InputIterator& iter, Distance n )
+	{
+		typedef typename iterator_traits< InputIterator >::iterator_category category;
+		detail::advance_impl( iter, n, category() );
+	}
+
+}
+
+#endif // NV_STL_ITERATOR_HH
Index: /trunk/nv/stl/limits.hh
===================================================================
--- /trunk/nv/stl/limits.hh	(revision 374)
+++ /trunk/nv/stl/limits.hh	(revision 374)
@@ -0,0 +1,396 @@
+// Copyright (C) 2015 ChaosForge Ltd
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+/**
+* @file limits.hh
+* @author Kornel Kisielewicz epyon@chaosforge.org
+* @brief STL limits library
+*/
+
+#ifndef NV_STL_LIMITS_HH
+#define NV_STL_LIMITS_HH
+
+#include <nv/core/common.hh>
+
+namespace nv
+{
+	struct limits
+	{
+		static const unsigned char uc_min = 0;
+		static const unsigned char uc_max = 255;
+		static const unsigned char uc_bit = sizeof( unsigned char ) * 8;
+		static const signed char sc_min = -128;
+		static const signed char sc_max = 127;
+		static const signed char sc_bit = sizeof( signed char ) * 8;
+		static const char c_min = ( char( 0 ) < char( -1 ) ? 0 : -128 );
+		static const char c_max = ( char( 0 ) < char( -1 ) ? 255 : 127 );
+		static const char c_bit = sizeof( char ) * 8;
+		static const unsigned short us_min = 0;
+		static const unsigned short us_max = 65535;
+		static const unsigned short us_bit = sizeof( unsigned short ) * 8;
+		static const signed short ss_min = -32768;
+		static const signed short ss_max = 32767;
+		static const signed short ss_bit = sizeof( signed short ) * 8;
+		static const unsigned int ui_min = 0;
+		static const unsigned int ui_max = 4294967295;
+		static const unsigned int ui_bit = sizeof( unsigned int ) * 8;
+		static const signed int si_min = -2147483648;
+		static const signed int si_max = 2147483647;
+		static const signed int si_bit = sizeof( signed int ) * 8;
+		static const unsigned long ul_min = 0;
+		static const unsigned long ul_max = 4294967295;
+		static const unsigned long ul_bit = sizeof( unsigned long ) * 8;
+		static const signed long sl_min = -2147483648;
+		static const signed long sl_max = 2147483647;
+		static const signed long sl_bit = sizeof( signed long ) * 8;
+		static const uint64 ull_min = 0;
+		static const uint64 ull_max = 18446744073709551615;
+		static const uint64 ull_bit = sizeof( uint64 ) * 8;
+		static const sint64 sll_min = -9223372036854775808;
+		static const sint64 sll_max = 9223372036854775807;
+		static const sint64 sll_bit = sizeof( sint64 ) * 8;
+
+		static const int f_dig        = 6;
+		static const int f_mant_dig   = 24;
+		static const int f_max_exp    = 128;
+		static const int f_max_10_exp = 38;
+		static const int f_min_exp    = -125;
+		static const int f_min_10_exp = -37;
+
+		static const int d_dig        = 15;
+		static const int d_mant_dig   = 53;
+		static const int d_max_exp    = 1024;
+		static const int d_max_10_exp = 308;
+		static const int d_min_exp    = -1021;
+		static const int d_min_10_exp = -307;
+
+		static const int ld_dig        = d_dig;
+		static const int ld_mant_dig   = d_mant_dig;
+		static const int ld_max_exp    = d_max_exp;
+		static const int ld_max_10_exp = d_max_10_exp;
+		static const int ld_min_exp    = d_min_exp;
+		static const int ld_min_10_exp = d_min_10_exp;
+	};
+
+	enum float_denorm_style
+	{
+		denorm_indeterminate = -1,
+		denorm_absent        = 0,
+		denorm_present       = 1
+	};
+
+	enum float_round_style
+	{
+		round_indeterminate       = -1,
+		round_toward_zero         = 0,
+		round_to_nearest          = 1,
+		round_toward_infinity     = 2,
+		round_toward_neg_infinity = 3
+	};
+
+	namespace detail
+	{
+		struct numeric_limits_base
+		{
+			static const float_denorm_style has_denorm = denorm_absent;
+			static const bool has_denorm_loss   = false;
+			static const bool has_infinity      = false;
+			static const bool has_quiet_NaN     = false;
+			static const bool has_signaling_NaN = false;
+			static const bool is_bounded        = false;
+			static const bool is_exact          = false;
+			static const bool is_iec559         = false;
+			static const bool is_integer        = false;
+			static const bool is_modulo         = false;
+			static const bool is_signed         = false;
+			static const bool is_specialized    = false;
+			static const bool tinyness_before   = false;
+			static const bool traps             = false;
+			static const float_round_style round_style = round_toward_zero;
+			static const int digits         = 0;
+			static const int digits10       = 0;
+			static const int max_digits10   = 0;
+			static const int max_exponent   = 0;
+			static const int max_exponent10 = 0;
+			static const int min_exponent   = 0;
+			static const int min_exponent10 = 0;
+			static const int radix          = 0;
+		};
+
+		struct numeric_limits_int_base : public numeric_limits_base
+		{
+			static const bool is_bounded     = true;
+			static const bool is_exact       = true;
+			static const bool is_integer     = true;
+			static const bool is_modulo      = true;
+			static const bool is_specialized = true;
+			static const int radix = 2;
+		};
+
+		struct numeric_limits_float_base : public numeric_limits_base
+		{
+			static const float_denorm_style has_denorm = denorm_present;
+			static const bool has_denorm_loss   = true;
+			static const bool has_infinity      = true;
+			static const bool has_quiet_NaN     = true;
+			static const bool has_signaling_NaN = true;
+			static const bool is_bounded        = true;
+			static const bool is_iec559         = true;
+			static const bool is_signed         = true;
+			static const bool is_specialized    = true;
+			static const bool tinyness_before   = true;
+			static const float_round_style round_style = round_to_nearest;
+			static const int radix = 2;
+		};
+
+	}
+
+	template< typename T >
+	struct numeric_limits : detail::numeric_limits_base
+	{
+		static NV_CONSTEXPR T min()           NV_NOEXCEPT { return T( 0 ); }
+		static NV_CONSTEXPR T max()           NV_NOEXCEPT { return T( 0 ); }
+		static NV_CONSTEXPR T lowest()        NV_NOEXCEPT { return T( 0 ); }
+		static NV_CONSTEXPR T epsilon()       NV_NOEXCEPT { return T( 0 ); }
+		static NV_CONSTEXPR T round_error()   NV_NOEXCEPT { return T( 0 ); }
+	};
+
+	template< typename T >
+	struct numeric_limits< const T > : numeric_limits < T > {};
+
+	template< typename T >
+	struct numeric_limits< volatile T > : numeric_limits < T > {};
+
+	template< typename T >
+	struct numeric_limits< const volatile T > : numeric_limits < T > {};
+
+	template<>
+	struct numeric_limits < bool > : detail::numeric_limits_int_base
+	{
+		static NV_CONSTEXPR bool min()           NV_NOEXCEPT { return false; }
+		static NV_CONSTEXPR bool max()           NV_NOEXCEPT { return true; }
+		static NV_CONSTEXPR bool lowest()        NV_NOEXCEPT { return false; }
+		static NV_CONSTEXPR bool epsilon()       NV_NOEXCEPT { return bool( 0 ); }
+		static NV_CONSTEXPR bool round_error()   NV_NOEXCEPT { return bool( 0 ); }
+
+		static const bool is_modulo = false;
+		static const bool is_signed = false;
+		static const int  digits    = 1;
+		static const int  digits10  = 0;
+	};
+
+	template<>
+	struct numeric_limits < char > : detail::numeric_limits_int_base
+	{
+		static NV_CONSTEXPR char min()           NV_NOEXCEPT { return limits::c_min; }
+		static NV_CONSTEXPR char max()           NV_NOEXCEPT { return limits::c_max; }
+		static NV_CONSTEXPR char lowest()        NV_NOEXCEPT { return limits::c_min; }
+		static NV_CONSTEXPR char epsilon()       NV_NOEXCEPT { return 0; }
+		static NV_CONSTEXPR char round_error()   NV_NOEXCEPT { return 0; }
+
+		static const bool is_signed = (limits::c_min < 0);
+		static const int  digits    = limits::c_bit - ( limits::c_min < 0 ? 1 : 0 );
+		static const int  digits10  = (limits::c_bit - ( limits::c_min < 0 ? 1 : 0 )) * 301 / 1000;
+	};
+
+	template<>
+	struct numeric_limits < unsigned char > : detail::numeric_limits_int_base
+	{
+		static NV_CONSTEXPR unsigned char min()           NV_NOEXCEPT { return limits::uc_min; }
+		static NV_CONSTEXPR unsigned char max()           NV_NOEXCEPT { return limits::uc_max; }
+		static NV_CONSTEXPR unsigned char lowest()        NV_NOEXCEPT { return limits::uc_min; }
+		static NV_CONSTEXPR unsigned char epsilon()       NV_NOEXCEPT { return 0; }
+		static NV_CONSTEXPR unsigned char round_error()   NV_NOEXCEPT { return 0; }
+
+		static const bool is_signed = false;
+		static const int  digits    = limits::c_bit;
+		static const int  digits10  = limits::c_bit  * 301 / 1000;
+	};
+
+	template<>
+	struct numeric_limits < signed char > : detail::numeric_limits_int_base
+	{
+		static NV_CONSTEXPR signed char min()           NV_NOEXCEPT { return limits::sc_min; }
+		static NV_CONSTEXPR signed char max()           NV_NOEXCEPT { return limits::sc_max; }
+		static NV_CONSTEXPR signed char lowest()        NV_NOEXCEPT { return limits::sc_min; }
+		static NV_CONSTEXPR signed char epsilon()       NV_NOEXCEPT { return 0; }
+		static NV_CONSTEXPR signed char round_error()   NV_NOEXCEPT { return 0; }
+
+		static const bool is_signed = true;
+		static const int  digits    = limits::c_bit - 1;
+		static const int  digits10  = (limits::c_bit - 1) * 301 / 1000;
+	};
+
+
+	template<>
+	struct numeric_limits < unsigned short > : detail::numeric_limits_int_base
+	{
+		static NV_CONSTEXPR unsigned short min()           NV_NOEXCEPT { return limits::us_min; }
+		static NV_CONSTEXPR unsigned short max()           NV_NOEXCEPT { return limits::us_max; }
+		static NV_CONSTEXPR unsigned short lowest()        NV_NOEXCEPT { return limits::us_min; }
+		static NV_CONSTEXPR unsigned short epsilon()       NV_NOEXCEPT { return 0; }
+		static NV_CONSTEXPR unsigned short round_error()   NV_NOEXCEPT { return 0; }
+
+		static const bool is_signed = false;
+		static const int  digits    = limits::us_bit;
+		static const int  digits10  = limits::us_bit * 301 / 1000;
+	};
+
+	template<>
+	struct numeric_limits < signed short > : detail::numeric_limits_int_base
+	{
+		static NV_CONSTEXPR signed short min()           NV_NOEXCEPT { return limits::ss_min; }
+		static NV_CONSTEXPR signed short max()           NV_NOEXCEPT { return limits::ss_max; }
+		static NV_CONSTEXPR signed short lowest()        NV_NOEXCEPT { return limits::ss_min; }
+		static NV_CONSTEXPR signed short epsilon()       NV_NOEXCEPT { return 0; }
+		static NV_CONSTEXPR signed short round_error()   NV_NOEXCEPT { return 0; }
+
+		static const bool is_signed = true;
+		static const int  digits    = limits::ss_bit - 1;
+		static const int  digits10  = ( limits::ss_bit - 1 ) * 301 / 1000;
+	};
+
+	template<>
+	struct numeric_limits < unsigned int > : detail::numeric_limits_int_base
+	{
+		static NV_CONSTEXPR unsigned int min()           NV_NOEXCEPT { return limits::ui_min; }
+		static NV_CONSTEXPR unsigned int max()           NV_NOEXCEPT { return limits::ui_max; }
+		static NV_CONSTEXPR unsigned int lowest()        NV_NOEXCEPT { return limits::ui_min; }
+		static NV_CONSTEXPR unsigned int epsilon()       NV_NOEXCEPT { return 0; }
+		static NV_CONSTEXPR unsigned int round_error()   NV_NOEXCEPT { return 0; }
+
+		static const bool is_signed = false;
+		static const int  digits    = limits::ui_bit;
+		static const int  digits10  = limits::ui_bit * 301 / 1000;
+	};
+
+	template<>
+	struct numeric_limits < signed int > : detail::numeric_limits_int_base
+	{
+		static NV_CONSTEXPR signed int min()           NV_NOEXCEPT { return limits::si_min; }
+		static NV_CONSTEXPR signed int max()           NV_NOEXCEPT { return limits::si_max; }
+		static NV_CONSTEXPR signed int lowest()        NV_NOEXCEPT { return limits::si_min; }
+		static NV_CONSTEXPR signed int epsilon()       NV_NOEXCEPT { return 0; }
+		static NV_CONSTEXPR signed int round_error()   NV_NOEXCEPT { return 0; }
+
+		static const bool is_signed = true;
+		static const int  digits    = limits::si_bit - 1;
+		static const int  digits10  = ( limits::si_bit - 1 ) * 301 / 1000;
+	};
+
+	template<>
+	struct numeric_limits < unsigned long > : detail::numeric_limits_int_base
+	{
+		static NV_CONSTEXPR unsigned long min()           NV_NOEXCEPT { return limits::ul_min; }
+		static NV_CONSTEXPR unsigned long max()           NV_NOEXCEPT { return limits::ul_max; }
+		static NV_CONSTEXPR unsigned long lowest()        NV_NOEXCEPT { return limits::ul_min; }
+		static NV_CONSTEXPR unsigned long epsilon()       NV_NOEXCEPT { return 0; }
+		static NV_CONSTEXPR unsigned long round_error()   NV_NOEXCEPT { return 0; }
+
+		static const bool is_signed = false;
+		static const int  digits    = limits::ul_bit;
+		static const int  digits10  = limits::ul_bit * 301 / 1000;
+	};
+
+	template<>
+	struct numeric_limits < signed long > : detail::numeric_limits_int_base
+	{
+		static NV_CONSTEXPR signed long min()           NV_NOEXCEPT { return limits::sl_min; }
+		static NV_CONSTEXPR signed long max()           NV_NOEXCEPT { return limits::sl_max; }
+		static NV_CONSTEXPR signed long lowest()        NV_NOEXCEPT { return limits::sl_min; }
+		static NV_CONSTEXPR signed long epsilon()       NV_NOEXCEPT { return 0; }
+		static NV_CONSTEXPR signed long round_error()   NV_NOEXCEPT { return 0; }
+
+		static const bool is_signed = true;
+		static const int  digits    = limits::sl_bit - 1;
+		static const int  digits10  = ( limits::sl_bit - 1 ) * 301 / 1000;
+	};
+
+	template<>
+	struct numeric_limits < uint64 > : detail::numeric_limits_int_base
+	{
+		static NV_CONSTEXPR uint64 min()           NV_NOEXCEPT { return limits::ull_min; }
+		static NV_CONSTEXPR uint64 max()           NV_NOEXCEPT { return limits::ull_max; }
+		static NV_CONSTEXPR uint64 lowest()        NV_NOEXCEPT { return limits::ull_min; }
+		static NV_CONSTEXPR uint64 epsilon()       NV_NOEXCEPT { return 0; }
+		static NV_CONSTEXPR uint64 round_error()   NV_NOEXCEPT { return 0; }
+
+		static const bool is_signed = false;
+		static const int  digits    = limits::ull_bit;
+		static const int  digits10  = limits::ull_bit * 301 / 1000;
+	};
+
+	template<>
+	struct numeric_limits < sint64 > : detail::numeric_limits_int_base
+	{
+		static NV_CONSTEXPR sint64 min()           NV_NOEXCEPT { return limits::sll_min; }
+		static NV_CONSTEXPR sint64 max()           NV_NOEXCEPT { return limits::sll_max; }
+		static NV_CONSTEXPR sint64 lowest()        NV_NOEXCEPT { return limits::sll_min; }
+		static NV_CONSTEXPR sint64 epsilon()       NV_NOEXCEPT { return 0; }
+		static NV_CONSTEXPR sint64 round_error()   NV_NOEXCEPT { return 0; }
+
+		static const bool is_signed = true;
+		static const int  digits    = limits::sll_bit - 1;
+		static const int  digits10  = ( limits::sll_bit - 1 ) * 301 / 1000;
+	};
+
+	template<>
+	struct numeric_limits < float > : detail::numeric_limits_float_base
+	{
+		static NV_CONSTEXPR float min()           NV_NOEXCEPT { return 1.175494351e-38F; }
+		static NV_CONSTEXPR float max()           NV_NOEXCEPT { return 3.402823466e+38F; }
+		static NV_CONSTEXPR float lowest()        NV_NOEXCEPT { return -max(); }
+		static NV_CONSTEXPR float epsilon()       NV_NOEXCEPT { return 1.192092896e-07F; }
+		static NV_CONSTEXPR float round_error()   NV_NOEXCEPT { return 0.5F; }
+
+		static const int digits         = limits::f_mant_dig;
+		static const int digits10       = limits::f_dig;
+		static const int max_digits10   = 2 + limits::f_dig * 301 / 1000;
+		static const int max_exponent   = limits::f_max_exp;
+		static const int max_exponent10 = limits::f_max_10_exp;
+		static const int min_exponent   = limits::f_min_exp;
+		static const int min_exponent10 = limits::f_min_10_exp;
+	};
+
+	template<>
+	struct numeric_limits < double > : detail::numeric_limits_float_base
+	{
+		static NV_CONSTEXPR double min()           NV_NOEXCEPT { return 2.2250738585072014e-308; }
+		static NV_CONSTEXPR double max()           NV_NOEXCEPT { return 1.7976931348623158e+308; }
+		static NV_CONSTEXPR double lowest()        NV_NOEXCEPT { return -max(); }
+		static NV_CONSTEXPR double epsilon()       NV_NOEXCEPT { return 2.2204460492503131e-016; }
+		static NV_CONSTEXPR double round_error()   NV_NOEXCEPT { return 0.5; }
+
+		static const int digits         = limits::d_mant_dig;
+		static const int digits10       = limits::d_dig;
+		static const int max_digits10   = 2 + limits::d_dig * 301 / 1000;
+		static const int max_exponent   = limits::d_max_exp;
+		static const int max_exponent10 = limits::d_max_10_exp;
+		static const int min_exponent   = limits::d_min_exp;
+		static const int min_exponent10 = limits::d_min_10_exp;
+	};
+
+	template<>
+	struct numeric_limits < long double > : detail::numeric_limits_float_base
+	{
+		static NV_CONSTEXPR long double min()           NV_NOEXCEPT { return 2.2250738585072014e-308; }
+		static NV_CONSTEXPR long double max()           NV_NOEXCEPT { return 1.7976931348623158e+308; }
+		static NV_CONSTEXPR long double lowest()        NV_NOEXCEPT { return -max(); }
+		static NV_CONSTEXPR long double epsilon()       NV_NOEXCEPT { return 2.2204460492503131e-016; }
+		static NV_CONSTEXPR long double round_error()   NV_NOEXCEPT { return 0.5; }
+
+		static const int digits         = limits::ld_mant_dig;
+		static const int digits10       = limits::ld_dig;
+		static const int max_digits10   = 2 + limits::ld_dig * 301 / 1000;
+		static const int max_exponent   = limits::ld_max_exp;
+		static const int max_exponent10 = limits::ld_max_10_exp;
+		static const int min_exponent   = limits::ld_min_exp;
+		static const int min_exponent10 = limits::ld_min_10_exp;
+	};
+
+}
+
+#endif // NV_STL_LIMITS_HH
Index: /trunk/nv/stl/math.hh
===================================================================
--- /trunk/nv/stl/math.hh	(revision 373)
+++ /trunk/nv/stl/math.hh	(revision 374)
@@ -84,7 +84,4 @@
 		static const size_t size = 4;
 	};
-
-	using glm::max;
-	using glm::min;
 
 	enum datatype
Index: /trunk/nv/stl/memory.hh
===================================================================
--- /trunk/nv/stl/memory.hh	(revision 373)
+++ /trunk/nv/stl/memory.hh	(revision 374)
@@ -18,5 +18,8 @@
 #include <nv/core/common.hh>
 #include <nv/stl/type_traits.hh>
-#include <iterator>
+#include <nv/stl/utility.hh>
+#include <nv/stl/iterator.hh>
+
+#include <type_traits>
 
 namespace nv
@@ -25,4 +28,182 @@
 	namespace detail
 	{
+		template < typename ForwardIterator, typename T >
+		void uninitialized_fill_impl( ForwardIterator first, ForwardIterator last, const T& value, true_type )
+		{
+			fill( first, last, value );
+		}
+
+		template < typename ForwardIterator, typename T >
+		void uninitialized_fill_impl( ForwardIterator first, ForwardIterator last, const T& value, false_type )
+		{
+			typedef typename iterator_traits< ForwardIterator >::value_type value_type;
+			ForwardIterator it( first );
+			for ( ; it != last; ++it )
+				::new( (void*)&*it ) value_type( value );
+		}
+
+		template < typename ForwardIterator, typename T >
+		ForwardIterator uninitialized_fill_n_impl( ForwardIterator first, size_t count, const T& value, true_type )
+		{
+			return fill_n( first, count, value );
+		}
+
+		template < typename ForwardIterator, typename T >
+		ForwardIterator uninitialized_fill_n_impl( ForwardIterator first, size_t count, const T& value, false_type )
+		{
+			typedef typename iterator_traits< ForwardIterator >::value_type value_type;
+			ForwardIterator it( first );
+			for ( ; count > 0; --count, ++it )
+				::new ( (void*)&*it ) value_type( value );
+			return it;
+		}
+
+		template < typename ForwardIterator >
+		inline void uninitialized_construct_impl( ForwardIterator first, ForwardIterator last, true_type )
+		{
+			fill_default( first, last );
+		}
+
+		template < typename ForwardIterator >
+		inline void uninitialized_construct_impl( ForwardIterator first, ForwardIterator last, false_type )
+		{
+			typedef typename iterator_traits< ForwardIterator >::value_type value_type;
+			ForwardIterator it( first );
+			for ( ; it != last; ++it )
+				::new( (void*)&*it ) value_type;
+		}
+
+		template < typename ForwardIterator >
+		inline ForwardIterator uninitialized_construct_n_impl( ForwardIterator first, size_t count, true_type )
+		{
+			return fill_default_n( first, count );
+		}
+
+		template < typename ForwardIterator >
+		inline ForwardIterator uninitialized_construct_n_impl( ForwardIterator first, size_t count, false_type )
+		{
+			typedef typename iterator_traits< ForwardIterator >::value_type value_type;
+			ForwardIterator it( first );
+			for ( ; count > 0; --count, ++it )
+				::new( (void*)&*it ) value_type;
+		}
+
+		template < typename ForwardIterator >
+		inline void uninitialized_destroy_impl( ForwardIterator, ForwardIterator, true_type )
+		{
+			// no-op
+		}
+
+		template < typename ForwardIterator >
+		inline void uninitialized_destroy_impl( ForwardIterator first, ForwardIterator last, false_type )
+		{
+			typedef typename iterator_traits< ForwardIterator >::value_type value_type;
+			ForwardIterator it( first );
+			for ( ; it != last; ++it )
+				( *it ).~value_type();
+		}
+
+		template < typename ForwardIterator >
+		inline ForwardIterator uninitialized_destroy_n_impl( ForwardIterator first, size_t count, true_type )
+		{
+			return first + count;
+		}
+
+		template < typename ForwardIterator >
+		inline ForwardIterator uninitialized_destroy_n_impl( ForwardIterator first, size_t count, false_type )
+		{
+			typedef typename iterator_traits< ForwardIterator >::value_type value_type;
+			ForwardIterator it( first );
+			for ( ; count > 0; --count, ++it )
+				( *it ).~value_type();
+			return it;
+		}
+
+	}
+
+	template < typename ForwardIterator, typename T >
+	inline void uninitialized_fill( ForwardIterator first, ForwardIterator last, const T& value )
+	{
+		typedef typename iterator_traits< ForwardIterator >::value_type value_type;
+		uninitialized_fill_impl( first, last, value, has_trivial_assign<value_type>() );
+	}
+
+	template < typename ForwardIterator, typename T >
+	inline void uninitialized_fill_n( ForwardIterator first, size_t count, const T& value )
+	{
+		typedef typename iterator_traits< ForwardIterator >::value_type value_type;
+		return uninitialized_fill_n_impl( first, count, value, has_trivial_assign<value_type>() );
+	}
+
+	template < typename T >
+	inline void raw_construct_object( void* object )
+	{
+		new (object)T;
+	}
+
+	template < typename T, typename ...Args >
+	inline void raw_construct_object( void* object, Args&&... params )
+	{
+		new (object)T( forward<Args>( params )... );
+	}
+
+	template < typename T, typename ...Args >
+	inline void construct_object( T* object, Args&&... params )
+	{
+		new (object)T( forward<Args>( params )... );
+	}
+
+	template < typename T >
+	inline void destroy_object( T* object )
+	{
+		object->~T();
+	}
+
+	template <typename TYPE>
+	void raw_destroy_object( void* object )
+	{
+		( (TYPE*)object )->TYPE::~TYPE();
+	}
+
+
+	template < typename ForwardIterator, typename ...Args >
+	inline void uninitialized_construct( ForwardIterator first, ForwardIterator last, Args&&... params )
+	{
+		typedef typename iterator_traits< ForwardIterator >::value_type value_type;
+		ForwardIterator it( first );
+		for ( ; it != last; ++it )
+			::new( (void*)&*it ) value_type( forward<Args>( params )... );
+	}
+
+	template < typename ForwardIterator >
+	inline void uninitialized_construct( ForwardIterator first, ForwardIterator last )
+	{
+		typedef typename iterator_traits< ForwardIterator >::value_type value_type;
+		uninitialized_construct_impl( first, last, has_trivial_constructor<value_type>() );
+	}
+
+	template < typename ForwardIterator >
+	inline ForwardIterator uninitialized_construct_n( ForwardIterator first, size_t count )
+	{
+		typedef typename iterator_traits< ForwardIterator >::value_type value_type;
+		return uninitialized_construct_n_impl( first, count, has_trivial_constructor<value_type>() );
+	}
+
+	template < typename ForwardIterator >
+	inline void uninitialized_destroy( ForwardIterator first, ForwardIterator last )
+	{
+		typedef typename iterator_traits< ForwardIterator >::value_type value_type;
+		uninitialized_destroy_impl( first, last, has_trivial_destructor<value_type>() );
+	}
+
+	template < typename ForwardIterator >
+	inline ForwardIterator uninitialized_destroy_n( ForwardIterator first, size_t count )
+	{
+		typedef typename iterator_traits< ForwardIterator >::value_type value_type;
+		return uninitialized_destroy_n_impl( first, count, has_trivial_destructor<value_type>() );
+	}
+
+	namespace detail
+	{
 		template < typename PARENT, typename T, bool CONST, typename BASE = empty_base_class<PARENT> >
 		class pointer_iterators {};
@@ -33,5 +214,5 @@
 		public:
 			typedef const T* const_iterator;
-			typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
+			typedef nv::reverse_iterator<const_iterator> const_reverse_iterator;
 
 			inline const_iterator begin() const { return const_iterator( static_cast<const PARENT&>( *this ).data() ); }
@@ -52,6 +233,6 @@
 			typedef T*       iterator;
 			typedef const T* const_iterator;
-			typedef std::reverse_iterator<iterator>       reverse_iterator;
-			typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
+			typedef nv::reverse_iterator<iterator>       reverse_iterator;
+			typedef nv::reverse_iterator<const_iterator> const_reverse_iterator;
 
 			inline const_iterator begin() const { return const_iterator( static_cast<const PARENT&>( *this ).data() ); }
@@ -226,4 +407,57 @@
 	};
 
+	template < typename T, size_t N >
+	class static_container_allocator
+	{
+	public:
+		typedef T value_type;
+		typedef typename aligned_array<T, N, NV_ALIGN_OF( T ) >::type storage;
+
+		static const bool   is_static  = true;
+		static const size_t type_align = NV_ALIGN_OF( T );
+		static const size_t type_size  = sizeof( T );
+
+		static_container_allocator()
+		{
+		}
+		bool resize( size_t new_size )
+		{
+			return true;
+		}
+		static NV_CONSTEXPR size_t capacity() { return N; }
+		static NV_CONSTEXPR size_t size() { return N; }
+		NV_CONSTEXPR T* data() { return static_cast<T*>( m_data ); }
+		NV_CONSTEXPR const T* data() const { return static_cast<const T*>( m_data ); }
+
+		storage m_data;
+	};
+
+	template < typename T >
+	class dynamic_container_allocator
+	{
+	public:
+		static const bool   is_static = false;
+		static const size_t type_size = sizeof( T );
+		static const size_t type_align = NV_ALIGN_OF( T );
+
+		dynamic_container_allocator()
+			: m_data(nullptr), m_size(0)
+		{
+		
+		}
+
+		static NV_CONSTEXPR size_t capacity() { return 0x80000000; }
+		size_t size() const { return m_size; }
+		T* data() { return static_cast<T*>( m_data ); }
+		const T* data() const { return static_cast<const T*>( m_data ); }
+
+		~dynamic_container_allocator()
+		{
+			delete m_data;
+		}
+
+		uint8* m_data;
+		size_t m_size;
+	};
 
 }
Index: /trunk/nv/stl/numeric.hh
===================================================================
--- /trunk/nv/stl/numeric.hh	(revision 374)
+++ /trunk/nv/stl/numeric.hh	(revision 374)
@@ -0,0 +1,105 @@
+// Copyright (C) 2015 ChaosForge Ltd
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+/**
+* @file numeric.hh
+* @author Kornel Kisielewicz epyon@chaosforge.org
+* @brief STL numeric library
+*/
+
+#ifndef NV_STL_NUMERIC_HH
+#define NV_STL_NUMERIC_HH
+
+#include <nv/core/common.hh>
+
+namespace nv
+{
+
+	template < typename InputIterator, typename T >
+	inline T accumulate( InputIterator first, InputIterator last, T init )
+	{
+		while ( first < last )
+			init += *first++;
+		return init;
+	}
+
+	template < typename InputIterator, typename T, typename BinaryFunction >
+	inline T accumulate( InputIterator first, InputIterator last, T init, BinaryFunction bin_op )
+	{
+		while ( first < last )
+			init = bin_op( init, *first++ );
+		return init;
+	}
+
+	template < typename ForwardIterator, typename T >
+	inline void iota( ForwardIterator first, ForwardIterator last, T value )
+	{
+		while ( first < last )
+			*first++ = value++;
+	}
+
+	template < typename InputIterator1, typename InputIterator2, typename T >
+	inline T inner_product( InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init )
+	{
+		while ( first1 < last1 )
+			init += *first1++ * *first2++;
+		return init;
+	}
+
+	template < typename InputIterator1, typename InputIterator2, typename T,
+		typename BinaryOperation1, typename BinaryOperation2 >
+	inline T inner_product( InputIterator1 first1, InputIterator1 last1, 
+		InputIterator2 first2, T init, BinaryOperation1 sum_op, BinaryOperation2 prod_op )
+	{
+		while ( first1 < last1 )
+			init = sum_op( init, prod_op( *first1++, *first2++ ) );
+		return init;
+	}
+
+	template < typename InputIterator, typename OutputIterator >
+	inline OutputIterator partial_sum( InputIterator first, InputIterator last, OutputIterator result )
+	{
+		if ( first < last )
+			*result = *first++;
+		while ( first < last )
+			*++result = *first++ + *result;
+		return result;
+	}
+
+	template < typename InputIterator, typename OutputIterator, typename BinaryOperation >
+	inline OutputIterator partial_sum( InputIterator first, InputIterator last, OutputIterator result, BinaryOperation sum_op )
+	{
+		if ( first < last )
+			*result = *first++;
+		while ( first < last )
+			*++result = sum_op( *first++, *result );
+		return result;
+	}
+
+	template < typename InputIterator, typename OutputIterator >
+	inline OutputIterator adjacent_difference( InputIterator first, InputIterator last, OutputIterator result )
+	{
+		if ( first < last )
+			*result++ = *first++;
+		while ( first < last )
+			*result++ = *first - *( first - 1 );
+		return result;
+	}
+
+	template < typename InputIterator, typename OutputIterator, typename BinaryOperation >
+	inline OutputIterator adjacent_difference( InputIterator first, InputIterator last, OutputIterator result, BinaryOperation diff_op )
+	{
+		if ( first < last )
+			*result++ = *first++;
+		while ( first < last )
+			*result++ = diff_op( *first, *( first - 1 ) );
+		return result;
+	}
+
+
+}
+
+#endif // NV_STL_NUMERIC_HH
Index: /trunk/nv/stl/string.hh
===================================================================
--- /trunk/nv/stl/string.hh	(revision 373)
+++ /trunk/nv/stl/string.hh	(revision 374)
@@ -22,5 +22,4 @@
 
 #include <string>
-#include <algorithm>
 #include <cstring>
 #include <sstream>
@@ -30,4 +29,5 @@
 #include <nv/stl/memory.hh>
 #include <nv/stl/exception.hh>
+#include <nv/stl/algorithm.hh>
 
 namespace nv
@@ -222,5 +222,5 @@
 	inline std::string& remove_chars( std::string& s, const std::string& chars ) 
 	{
-		s.erase(remove_if(s.begin(), s.end(), 
+		s.erase(nv::remove_if(s.begin(), s.end(), 
 			[&chars](const char& c) {
 				return chars.find(c) != std::string::npos;
@@ -235,5 +235,5 @@
 		if ( std::string::npos != lastdot )
 			ext = filename.substr( lastdot + 1 );
-		std::transform( ext.begin(), ext.end(), ext.begin(), ::tolower );
+		transform_seq( ext.begin(), ext.end(), ext.begin(), [=] ( char val ) { return char( ::tolower( val ) ); } );
 		return ext;
 	}
@@ -346,6 +346,6 @@
 		typedef pointer        const_iterator;
 		typedef const_iterator iterator;
-		typedef std::size_t    size_type;
-		typedef std::ptrdiff_t difference_type;
+		typedef size_t         size_type;
+		typedef ptrdiff_t      difference_type;
 
 		static NV_CONSTEXPR_CONST size_type npos = size_type( -1 );
@@ -373,5 +373,5 @@
 		int compare( const string_base& rhs ) const
 		{
-			int cmp = std::memcmp( m_data, rhs.m_data, ( std::min )( m_size, rhs.m_size ) );
+			int cmp = std::memcmp( m_data, rhs.m_data, ( nv::min )( m_size, rhs.m_size ) );
 			return cmp != 0 ? cmp : ( m_size == rhs.m_size ? 0 : m_size < rhs.m_size ? -1 : 1 );
 		}
@@ -389,36 +389,36 @@
 		{
 			if ( pos >= m_size ) return npos;
-			const_iterator it = std::search( this->cbegin() + ( difference_type ) pos, this->cend(), s.cbegin(), s.cend() );
-			return it == this->cend() ? npos : ( size_type )std::distance( this->cbegin(), it );
+			const_iterator it = search( this->cbegin() + ( difference_type ) pos, this->cend(), s.cbegin(), s.cend() );
+			return it == this->cend() ? npos : ( size_type )distance( this->cbegin(), it );
 		}
 		size_type find( char c, size_type pos = 0 ) const
 		{
 			if ( pos >= m_size ) return npos;
-			const_iterator it = std::find_if( this->cbegin() + ( difference_type ) pos, this->cend(), [=] ( char val ) { return val == c; } );
-			return it == this->cend() ? npos : ( size_type )std::distance( this->cbegin(), it );
+			const_iterator it = find_if( this->cbegin() + ( difference_type ) pos, this->cend(), [=] ( char val ) { return val == c; } );
+			return it == this->cend() ? npos : ( size_type )distance( this->cbegin(), it );
 		}
 		size_type rfind( const string_base& s, size_type pos = 0 ) const
 		{
 			if ( pos >= m_size ) return npos;
-			const_reverse_iterator it = std::search( this->crbegin() + ( difference_type ) pos, this->crend(), s.crbegin(), s.crend() );
-			return it == this->crend() ? npos : m_size - 1 - ( size_type )std::distance( this->crbegin(), it );
+			const_reverse_iterator it = search( this->crbegin() + ( difference_type ) pos, this->crend(), s.crbegin(), s.crend() );
+			return it == this->crend() ? npos : m_size - 1 - ( size_type )distance( this->crbegin(), it );
 		}
 		size_type rfind( char c, size_type pos = 0 ) const
 		{
 			if ( pos >= m_size ) return npos;
-			const_reverse_iterator it = std::find_if( this->crbegin() + ( difference_type ) pos, this->crend(), [=] ( char val ) { return val == c; } );
-			return it == this->crend() ? npos : m_size - 1 - ( size_type )std::distance( this->crbegin(), it );
+			const_reverse_iterator it = find_if( this->crbegin() + ( difference_type ) pos, this->crend(), [=] ( char val ) { return val == c; } );
+			return it == this->crend() ? npos : m_size - 1 - ( size_type )distance( this->crbegin(), it );
 		}
 		size_type find_first_of( char c ) const { return find( c ); }
 		size_type find_first_of( const string_base& s ) const
 		{
-			const_iterator it = std::find_first_of( this->cbegin(), this->cend(), s.cbegin(), s.cend() );
-			return it == this->cend() ? npos : ( size_type )std::distance( this->cbegin(), it );
+			const_iterator it = nv::find_first_of( this->cbegin(), this->cend(), s.cbegin(), s.cend() );
+			return it == this->cend() ? npos : ( size_type )distance( this->cbegin(), it );
 		}
 		size_type find_last_of( char c )  const { return rfind( c ); }
 		size_type find_last_of( const string_base& s ) const
 		{
-			const_reverse_iterator it = std::find_first_of( this->crbegin(), this->crend(), s.cbegin(), s.cend() );
-			return it == this->crend() ? npos : m_size - 1 - ( size_type )std::distance( this->crbegin(), it );
+			const_reverse_iterator it = nv::find_first_of( this->crbegin(), this->crend(), s.cbegin(), s.cend() );
+			return it == this->crend() ? npos : m_size - 1 - ( size_type )distance( this->crbegin(), it );
 		}
 		size_type find_first_not_of( const string_base& s ) const
@@ -426,5 +426,5 @@
 			for ( const_iterator it = this->cbegin(); it != this->cend(); ++it )
 				if ( 0 == std::memchr( s.m_data, *it, s.m_size ) )
-					return ( size_type )std::distance( this->cbegin(), it );
+					return ( size_type )distance( this->cbegin(), it );
 			return npos;
 		}
@@ -433,5 +433,5 @@
 			for ( const_iterator it = this->cbegin(); it != this->cend(); ++it )
 				if ( c != *it )
-					return ( size_type )std::distance( this->cbegin(), it );
+					return ( size_type )distance( this->cbegin(), it );
 			return npos;
 		}
@@ -440,5 +440,5 @@
 			for ( const_reverse_iterator it = this->crbegin(); it != this->crend(); ++it )
 				if ( 0 == std::memchr( s.m_data, *it, s.m_size ) )
-					return m_size - 1 - ( size_type )std::distance( this->crbegin(), it );;
+					return m_size - 1 - ( size_type )distance( this->crbegin(), it );;
 			return npos;
 		}
@@ -447,5 +447,5 @@
 			for ( const_reverse_iterator it = this->crbegin(); it != this->crend(); ++it )
 				if ( c != *it )
-					return m_size - 1 - ( size_type )std::distance( this->crbegin(), it );
+					return m_size - 1 - ( size_type )distance( this->crbegin(), it );
 			return npos;
 		}
@@ -454,5 +454,5 @@
 		string_ref substr( size_type p, size_type n = npos ) const;
 
-		inline std::size_t hash() const
+		inline size_t hash() const
 		{
 			const char* str = m_data;
Index: /trunk/nv/stl/type_info.hh
===================================================================
--- /trunk/nv/stl/type_info.hh	(revision 374)
+++ /trunk/nv/stl/type_info.hh	(revision 374)
@@ -0,0 +1,65 @@
+// Copyright (C) 2015 ChaosForge Ltd
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+/**
+* @file type_info.hh
+* @author Kornel Kisielewicz epyon@chaosforge.org
+* @brief type info
+*/
+// TODO: remove typeinfo?
+
+#ifndef NV_STL_TYPE_INFO_HH
+#define NV_STL_TYPE_INFO_HH
+
+#include <nv/core/common.hh>
+#include <typeinfo>
+
+namespace nv
+{
+
+	class type_index
+	{
+	public:
+		inline type_index( const std::type_info& info ) : m_type_info( &info ) {}
+		inline size_t hash_code() const { return m_type_info->hash_code(); }
+		inline const char *name() const { return m_type_info->name(); }
+
+		inline bool operator==( const type_index& rhs ) const
+		{
+			return ( *m_type_info == *rhs.m_type_info );
+		}
+
+		inline bool operator!=( const type_index& rhs ) const
+		{
+			return ( !( *this == rhs ) );
+		}
+
+		inline bool operator<( const type_index& rhs ) const
+		{
+			return ( m_type_info->before( *rhs.m_type_info ) );
+		}
+
+		inline bool operator>=( const type_index& rhs ) const
+		{
+			return ( !( *this < rhs ) );
+		}
+
+		inline bool operator>( const type_index& rhs ) const
+		{
+			return ( rhs < *this );
+		}
+
+		inline bool operator<=( const type_index& rhs ) const
+		{
+			return ( !( rhs < *this ) );
+		}
+
+	private:
+		const std::type_info* m_type_info;
+	};
+
+}
+
+#endif // NV_STL_TYPE_INFO_HH
Index: /trunk/nv/stl/type_traits.hh
===================================================================
--- /trunk/nv/stl/type_traits.hh	(revision 373)
+++ /trunk/nv/stl/type_traits.hh	(revision 374)
@@ -10,5 +10,4 @@
  */
 // TODO: "......" function match version?
-// TODO: remove type_traits
 // TODO: remove typeinfo?
 
@@ -18,72 +17,52 @@
 #include <nv/core/common.hh>
 
+#include <type_traits>
 namespace nv
 {
 
-	template< typename T, T VALUE>
-	struct integral_constant
-	{
-		static const T value = VALUE;
-		typedef T value_type;
-		typedef integral_constant<T, VALUE> type;
-		NV_CONSTEXPR operator value_type() const { return ( value ); }
-	};
-
-	typedef integral_constant<bool, true> true_type;
-	typedef integral_constant<bool, false> false_type;
-
-	template< bool TEST, typename T = void>
-	struct enable_if {};
-
-	template< typename T > 
-	struct enable_if< true, T >
-	{
-		typedef T type;
-	};
-
-	template< bool TEST, typename T1, typename T2 >
-	struct conditional
-	{
-		typedef T2 type;
-	};
-
-	template< typename T1, typename T2>
-	struct conditional < true, T1, T2 >
-	{
-		typedef T1 type;
-	};
-
-	template< typename T1, typename T2 >
+	template < typename T1, typename T2 >
 	struct is_same : false_type {};
 
-	template< typename T >
+	template < typename T >
 	struct is_same < T, T > : true_type {};
 
-	template< typename T >
+	template < typename T >
 	struct is_array : false_type {};
 
-	template< typename T, size_t N >
+	template < typename T, size_t N >
 	struct is_array < T[N] > : true_type {};
 
-	template< typename T >
+	template < typename T >
 	struct is_array < T[] > : true_type {};
 
-	template< typename T >
+	template < typename T >
 	struct is_lvalue_reference : false_type {};
 
-	template< typename T >
+	template < typename T >
 	struct is_lvalue_reference < T& > : true_type{};
 
-	template< typename T >
+	template < typename T >
 	struct is_rvalue_reference : false_type {};
 
-	template< typename T >
+	template < typename T >
 	struct is_rvalue_reference < T&& > : true_type{};
 
+	template < typename _Ty>
+	struct is_reference : integral_constant < bool, is_lvalue_reference<_Ty>::value || is_rvalue_reference<_Ty>::value > {};
+
 	template < typename T >
 	struct is_enum : integral_constant < bool, __is_enum( T ) > {};
 
-	template < typename T >
-	struct is_pod : integral_constant < bool, __is_pod( T ) > {};
+	// TODO: these seem to simple compared to MSVC/GCC - so we'll leave them in
+	// detail - research why it is so.
+	template < typename T >
+	struct is_const : false_type {};
+	template < typename T >
+	struct is_const < T const > : true_type{};
+	template < typename T >
+	struct is_volatile : false_type {};
+	template < typename T >
+	struct is_volatile < T volatile > : true_type{};
+	// TODO END
 
 	template< typename T >
@@ -222,16 +201,4 @@
 	namespace detail
 	{
-		// TODO: these seem to simple compared to MSVC/GCC - so we'll leave them in
-		// detail - research why it is so.
-		template < typename T >
-		struct is_const : false_type {};
-		template < typename T >
-		struct is_const < T const > : true_type {};
-		template < typename T > 
-		struct is_volatile : false_type {};
-		template < typename T >
-		struct is_volatile < T volatile > : true_type {};
-		// TODO END
-
 		template< typename T, bool CONST, bool VOLATILE>
 		struct cv_selector;
@@ -454,4 +421,31 @@
 #endif
 
+	template <typename T>
+	struct is_empty : integral_constant < bool, __is_empty( T ) > {};
+
+	template < typename T >
+	struct is_pod : integral_constant < bool, __is_pod( T ) > {};
+
+	template < typename T >
+	struct has_trivial_constructor : integral_constant < bool, __has_trivial_constructor( T ) || __is_pod( T ) > {};
+
+#if NV_COMPILER == NV_MSVC
+	template < typename T >
+	struct has_trivial_copy : integral_constant < bool, ( __has_trivial_copy( T ) || __is_pod( T ) ) && !is_volatile<T>::value > {};
+#else
+	template < typename T >
+	struct has_trivial_copy : integral_constant < bool, ( __has_trivial_copy( T ) || __is_pod( T ) ) && ( !is_volatile<T>::value && !is_reference<T>::value ) > {};
+#endif
+
+	template < typename T >
+	struct has_trivial_assign : integral_constant < bool, ( __has_trivial_assign( T ) || __is_pod( T ) ) && ( !is_volatile<T>::value && !is_const<T>::value ) > {};
+
+	template < typename T >
+	struct has_trivial_destructor : integral_constant < bool, __has_trivial_destructor( T ) || __is_pod( T ) > {};
+
+	template < typename T >
+	struct has_virtual_destructor : integral_constant < bool, __has_virtual_destructor( T ) > {};
+
+
 	namespace detail
 	{
@@ -606,4 +600,76 @@
 	};
 
+#if NV_COMPILER == NV_MSVC
+	typedef double max_align_t;
+#elif NV_PLATFORM == NV_APPLE
+	typedef long double max_align_t;
+#else
+	namespace detail
+	{
+		class aligned_dummy;
+		typedef void( *aligned_fptr )( );
+		typedef int( aligned_dummy::*aligned_memptr );
+		typedef int ( aligned_dummy::*aligned_memfptr )( );
+	}
+
+	union max_align_t
+	{
+		double                  dummy0;
+		long double             dummy1;
+		void*                   dummy2;
+		sint64                  dummy3;
+		detail::aligned_fptr    dummy4;
+		detail::aligned_memptr  dummy5;
+		detail::aligned_memfptr dummy6;
+	};
+#endif
+
+#if NV_COMPILER == NV_CLANG
+	template< typename T, size_t Size, size_t Align >
+	struct aligned_array
+	{
+		typedef T alignas( Align ) type[Size];
+	};
+#elif NV_COMPILER == NV_GNUC
+ 	template< typename T, size_t Size, size_t Align >
+ 	struct aligned_array
+ 	{
+		typedef T __attribute__((aligned( Align ))) type[Size];
+	};
+#else
+	// TODO: remove this shit after moving to MSVC 2015
+	template< typename T, size_t Size, size_t Align >
+	struct aligned_array;
+
+	// According to LLVM ( https://llvm.org/svn/llvm-project/llvm/trunk/include/llvm/Support/AlignOf.h )
+	// MSVC has problems with align below 16...
+#define NV_ALIGNED_ARRAY(N) \
+	template< typename T, size_t Size > \
+	struct aligned_array< T, Size, N >  \
+	{ \
+		typedef __declspec( align(N) ) T type[Size]; \
+	}; 
+
+NV_ALIGNED_ARRAY( 1 )
+NV_ALIGNED_ARRAY( 2 )
+NV_ALIGNED_ARRAY( 4 )
+NV_ALIGNED_ARRAY( 8 )
+NV_ALIGNED_ARRAY( 16 )
+NV_ALIGNED_ARRAY( 32 )
+NV_ALIGNED_ARRAY( 64 )
+NV_ALIGNED_ARRAY( 128 )
+
+#undef NV_ALIGNED_ARRAY
+#endif
+
+	template< size_t Size, size_t Align = NV_ALIGN_OF( max_align_t ) >
+	struct aligned_storage
+	{
+		struct type
+		{
+			typename aligned_array< unsigned char, Size, Align >::type data;
+		};
+	};
+
 }
 
Index: /trunk/nv/stl/utility.hh
===================================================================
--- /trunk/nv/stl/utility.hh	(revision 373)
+++ /trunk/nv/stl/utility.hh	(revision 374)
@@ -1,3 +1,3 @@
-// Copyright (C) 2014 ChaosForge Ltd
+// Copyright (C) 2015 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -39,4 +39,5 @@
 	}
 
+	// TODO: change to swap once you get rid of STL
 	template< typename T >
 	void swap( T& x, T& y )
@@ -47,5 +48,17 @@
 	}
 
+	template < typename T >
+	inline const T&	max( const T& a, const T& b )
+	{
+		return a < b ? b : a;
+	}
+
+	template < typename T >
+	inline const T&	min( const T& a, const T& b )
+	{
+		return a > b ? b : a;
+	}
+
 }
 
-#endif NV_STL_UTILITY_HH
+#endif // NV_STL_UTILITY_HH
Index: /trunk/src/curses/curses_terminal.cc
===================================================================
--- /trunk/src/curses/curses_terminal.cc	(revision 373)
+++ /trunk/src/curses/curses_terminal.cc	(revision 374)
@@ -65,5 +65,5 @@
 	}
 	mvaddch( p.y-1, p.x-1, ch );
-	move( m_cursor.y-1, m_cursor.x-1 );
+	::move( m_cursor.y-1, m_cursor.x-1 );
 }
 
@@ -80,5 +80,5 @@
 	m_update_needed = true;
 	::clear();
-	move( m_cursor.y-1, m_cursor.x-1 );
+	::move( m_cursor.y-1, m_cursor.x-1 );
 }
 
@@ -160,5 +160,5 @@
 {
 	terminal::set_cursor( p );
-	move( m_cursor.y-1, m_cursor.x-1 );
+	::move( m_cursor.y-1, m_cursor.x-1 );
 }
 
Index: /trunk/src/engine/particle_engine.cc
===================================================================
--- /trunk/src/engine/particle_engine.cc	(revision 373)
+++ /trunk/src/engine/particle_engine.cc	(revision 374)
@@ -7,7 +7,7 @@
 #include <nv/interface/device.hh>
 #include <nv/core/random.hh>
+#include <nv/stl/utility.hh>
 #include <nv/lua/lua_glm.hh>
 #include <nv/core/logging.hh>
-#include <cmath>
 
 static const char *nv_particle_engine_vertex_shader_world =
@@ -203,5 +203,5 @@
 	if ( datap->average )
 	{
-		float norm_factor = glm::min( factor, 1.0f );
+		float norm_factor = nv::min( factor, 1.0f );
 		for ( uint32 i = 0; i < count; ++i ) 
 			p[i].velocity = datap->force_vector * norm_factor + p[i].velocity * ( 1.0f - norm_factor );
@@ -696,5 +696,5 @@
 			{
 				info->count--;
-				std::swap( info->particles[i], info->particles[info->count] );
+				swap( info->particles[i], info->particles[info->count] );
 			}
 		}
Index: /trunk/src/formats/md2_loader.cc
===================================================================
--- /trunk/src/formats/md2_loader.cc	(revision 373)
+++ /trunk/src/formats/md2_loader.cc	(revision 374)
@@ -238,5 +238,5 @@
 }
 
-size_t md2_loader::get_max_frames() const
+nv::size_t md2_loader::get_max_frames() const
 {
 	return static_cast< size_t >( ((md2_t*)m_md2)->header.num_frames );
Index: /trunk/src/formats/md3_loader.cc
===================================================================
--- /trunk/src/formats/md3_loader.cc	(revision 373)
+++ /trunk/src/formats/md3_loader.cc	(revision 374)
@@ -172,5 +172,5 @@
 	source.read( surface->vertices, sizeof( md3_vertex_t ), static_cast<size_t>( surface->header.num_verts * surface->header.num_frames ) );
 
-	if ( source.tell() != static_cast<std::size_t>( pos + surface->header.ofs_end ) ) return false;
+	if ( source.tell() != static_cast<size_t>( pos + surface->header.ofs_end ) ) return false;
 
 	return true;
Index: /trunk/src/formats/md5_loader.cc
===================================================================
--- /trunk/src/formats/md5_loader.cc	(revision 373)
+++ /trunk/src/formats/md5_loader.cc	(revision 374)
@@ -344,5 +344,6 @@
 		vtc.tangent  = glm::vec3(0);
 
-		std::sort( weights + start_weight, weights + start_weight + weight_count, [](const md5_weight& a, const md5_weight& b) -> bool { return a.bias > b.bias; } );
+		stable_sort( weights + start_weight, weights + start_weight + weight_count, [] ( const md5_weight& a, const md5_weight& b ) -> bool { return a.bias > b.bias; } );
+		//std::sort( weights + start_weight, weights + start_weight + weight_count, [](const md5_weight& a, const md5_weight& b) -> bool { return a.bias > b.bias; } );
 
 		if ( weight_count > 4 )
Index: /trunk/src/formats/obj_loader.cc
===================================================================
--- /trunk/src/formats/obj_loader.cc	(revision 373)
+++ /trunk/src/formats/obj_loader.cc	(revision 374)
@@ -53,6 +53,6 @@
 	std::string next_name;
 
-	std::size_t size;
-	bool        eof;
+	size_t size;
+	bool   eof;
 
 	obj_reader();
@@ -172,5 +172,5 @@
 {
 	mesh_data_reader( bool normals ) : m_normals( normals ) {}
-	virtual std::size_t add_face( uint32* vi, uint32* ti, uint32* ni, size_t count )
+	virtual size_t add_face( uint32* vi, uint32* ti, uint32* ni, size_t count )
 	{
 		if ( count < 3 ) return 0; // TODO : report error?
@@ -178,5 +178,5 @@
 		// TODO : support if normals not present;
 		vec3 nullvec;
-		std::size_t result = 0;
+		size_t result = 0;
 		// Simple triangulation - obj's shouldn't have more than quads anyway
 
@@ -278,5 +278,5 @@
 		}
 
-		for (std::size_t a = 0; a < count; ++a )
+		for (size_t a = 0; a < count; ++a )
 		{
 			const vec3& n = m_data[a].normal;
Index: /trunk/src/gfx/image.cc
===================================================================
--- /trunk/src/gfx/image.cc	(revision 373)
+++ /trunk/src/gfx/image.cc	(revision 374)
@@ -4,6 +4,4 @@
 
 #include "nv/gfx/image.hh"
-
-#include <algorithm>
 
 using namespace nv;
Index: /trunk/src/io/c_stream.cc
===================================================================
--- /trunk/src/io/c_stream.cc	(revision 373)
+++ /trunk/src/io/c_stream.cc	(revision 374)
@@ -6,5 +6,4 @@
 #include <sys/stat.h> 
 #include "nv/io/c_stream.hh"
-#include <limits>
 
 using namespace nv;
Index: /trunk/src/io/std_stream.cc
===================================================================
--- /trunk/src/io/std_stream.cc	(revision 373)
+++ /trunk/src/io/std_stream.cc	(revision 374)
@@ -8,5 +8,6 @@
 
 #include "nv/io/std_stream.hh"
-#include <algorithm>
+#include "nv/stl/math.hh"
+#include "nv/stl/utility.hh"
 
 using namespace nv;
@@ -15,6 +16,6 @@
 	: m_stream( source )
 	, m_owner( owner )
-	, m_buffer( std::max(bsize, put_back) + put_back )
-	, m_put_back( std::max( put_back, std::size_t( 1 ) ) )
+	, m_buffer( nv::max(bsize, put_back) + put_back )
+	, m_put_back( nv::max( put_back, std::size_t( 1 ) ) )
 {
 	char *end = &m_buffer.front() + m_buffer.size();
Index: /trunk/src/lib/curses.cc
===================================================================
--- /trunk/src/lib/curses.cc	(revision 373)
+++ /trunk/src/lib/curses.cc	(revision 374)
@@ -11,4 +11,5 @@
 #include "nv/core/library.hh"
 
+#define FILE void
 #define NV_CURSES_FUN( rtype, fname, fparams ) rtype (*fname) fparams = nullptr;
 #include <nv/lib/detail/curses_functions.inc>
@@ -21,5 +22,5 @@
 	curses_library.open( path );
 
-#	define NV_CURSES_FUN( rtype, fname, fparams ) *(void **) (&fname) = curses_library.get(#fname);
+#	define NV_CURSES_FUN( rtype, fname, fparams ) *(void **) (&::fname) = curses_library.get(#fname);
 #	include <nv/lib/detail/curses_functions.inc>
 #	undef NV_CURSES_FUN
Index: /trunk/src/lua/lua_area.cc
===================================================================
--- /trunk/src/lua/lua_area.cc	(revision 373)
+++ /trunk/src/lua/lua_area.cc	(revision 374)
@@ -79,5 +79,5 @@
 {
 	nv::rectangle* a = to_parea( L, 1 );
-	std::size_t l;
+	nv::size_t l;
 	const char* index = lua_tolstring( L, 2, &l );
 	if ( l == 1 && index[0] == 'a' )
@@ -101,5 +101,5 @@
 {
 	nv::rectangle* a = to_parea( L, 1 );
-	std::size_t l;
+	nv::size_t l;
 	const char* index = lua_tolstring( L, 2, &l );
 	nv::ivec2 value( to_coord( L, 3 ) );
Index: /trunk/src/lua/lua_map_tile.cc
===================================================================
--- /trunk/src/lua/lua_map_tile.cc	(revision 373)
+++ /trunk/src/lua/lua_map_tile.cc	(revision 374)
@@ -7,7 +7,8 @@
 #include "nv/lua/lua_map_tile.hh"
 
-#include <numeric>
 #include "nv/lua/lua_map_area.hh"
 #include "nv/stl/flags.hh"
+#include "nv/stl/numeric.hh"
+#include "nv/stl/algorithm.hh"
 #include "nv/core/random.hh"
 #include "nv/lua/lua_area.hh"
@@ -59,5 +60,5 @@
 	map_tile tile;
 
-	tile.size_y = (nv::uint16)( std::count( code.begin(), code.end(), '\n' ) + 1 );
+	tile.size_y = (nv::uint16)( nv::count( code.begin(), code.end(), '\n' ) + 1 );
 	tile.size_x = (nv::uint16)( code.find( '\n' ) );
 	if ( tile.size_x == 0 )
@@ -236,6 +237,6 @@
 	nv::uint16 org_x = tile->size_x;
 	nv::uint16 org_y = tile->size_y;
-	nv::uint16 new_x = (nv::uint16)std::accumulate( sizes_x.begin(), sizes_x.end(), 0 );
-	nv::uint16 new_y = (nv::uint16)std::accumulate( sizes_y.begin(), sizes_y.end(), 0 );
+	nv::uint16 new_x = ( nv::uint16 )nv::accumulate( sizes_x.begin(), sizes_x.end(), 0 );
+	nv::uint16 new_y = ( nv::uint16 )nv::accumulate( sizes_y.begin(), sizes_y.end(), 0 );
 
 	nv::uint8* data = new nv::uint8[ new_x * new_y ];
Index: /trunk/src/stl/string.cc
===================================================================
--- /trunk/src/stl/string.cc	(revision 373)
+++ /trunk/src/stl/string.cc	(revision 374)
@@ -28,5 +28,5 @@
 }
 
-size_t nv::sint32_to_buffer( sint32 n, char* str )
+nv::size_t nv::sint32_to_buffer( sint32 n, char* str )
 {
 	char* s = str;
@@ -43,5 +43,5 @@
 }
 
-size_t nv::sint64_to_buffer( sint64 n, char* str )
+nv::size_t nv::sint64_to_buffer( sint64 n, char* str )
 {
 	char* s = str;
@@ -58,5 +58,5 @@
 }
 
-size_t nv::uint32_to_buffer( uint32 n, char* str )
+nv::size_t nv::uint32_to_buffer( uint32 n, char* str )
 {
 	char* s = str;
@@ -71,5 +71,5 @@
 }
 
-size_t nv::uint64_to_buffer( uint64 n, char* str )
+nv::size_t nv::uint64_to_buffer( uint64 n, char* str )
 {
 	char* s = str;
@@ -84,5 +84,5 @@
 }
 
-size_t nv::f32_to_buffer( f32 n, char* str )
+nv::size_t nv::f32_to_buffer( f32 n, char* str )
 {
 #if NV_COMPILER == NV_MSVC
@@ -95,5 +95,5 @@
 }
 
-size_t nv::f64_to_buffer( f64 n, char* str )
+nv::size_t nv::f64_to_buffer( f64 n, char* str )
 {
 #if NV_COMPILER == NV_MSVC
