Index: trunk/nv/ecs/component.hh
===================================================================
--- trunk/nv/ecs/component.hh	(revision 541)
+++ trunk/nv/ecs/component.hh	(revision 542)
@@ -36,4 +36,5 @@
 			typename Ecs,
 			typename Component,
+			typename Handler,
 			template < typename, typename > class IndexTable = index_table
 		>
@@ -41,23 +42,25 @@
 		{
 		public:
-			typedef Ecs                                    ecs_type;
-			typedef typename ecs_type::message             message_type;
-			typedef typename ecs_type::handle_type         handle_type;
-			typedef typename ecs_type::time_type           time_type;
-			typedef IndexTable< handle_type, sint32 >      index_table_type;
-			typedef Component                              value_type;
-			typedef Component                              component_type;
-			typedef vector< value_type >                   storage_type;
-			typedef typename index_table_type::index_type  index_type;
+			typedef Ecs                                     ecs_type;
+			typedef typename ecs_type::message              message_type;
+			typedef typename ecs_type::handle_type          handle_type;
+			typedef typename ecs_type::time_type            time_type;
+			typedef IndexTable< handle_type, sint32 >       index_table_type;
+			typedef Component                               value_type;
+			typedef Component                               component_type;
+			typedef component_storage_handler< value_type > storage_type;
+//			typedef vector< value_type > storage_type;
+			typedef typename index_table_type::index_type   index_type;
 
-			typedef typename storage_type::iterator        iterator;
-			typedef typename storage_type::const_iterator  const_iterator;
-			typedef typename storage_type::reference       reference;
-			typedef typename storage_type::const_reference const_reference;
+			typedef typename storage_type::iterator         iterator;
+			typedef typename storage_type::const_iterator   const_iterator;
+			typedef typename storage_type::reference        reference;
+			typedef typename storage_type::const_reference  const_reference;
 
 			component( ecs_type& a_ecs, string_view a_name, uint32 reserve = 0 ) 
 				: m_ecs( a_ecs )
 			{
-				m_ecs.register_component<component_type>( a_name, this );
+				m_ecs.register_component<component_type, Handler>( a_name, this );
+
 				if ( reserve != 0 )
 				{
@@ -99,8 +102,8 @@
 			virtual void clear()
 			{
-				for ( uint32 i = 0; i < m_data.size(); ++i )
-					destroy( &m_data[i] );
+ 				for ( uint32 i = 0; i < m_data.size(); ++i )
+ 					destroy( &m_data[i] );
 				m_index.clear();
-				m_data.clear();
+ 				m_data.clear();
 			}
 
@@ -119,5 +122,5 @@
 			const void* get_raw( handle_type h ) const { return get( h ); }
 
-			virtual void remove( handle_type h )
+			virtual void remove( handle_type h ) override
 			{
 				value_type* v = get( h );
@@ -138,9 +141,4 @@
 			}
 
-			virtual bool handle_message( const message_type& )
-			{
-				return true;
-			}
-
 			~component()
 			{
@@ -148,5 +146,5 @@
 			}
 			
-			inline handle_type get_handle( index_type i ) const { return m_index.get_handle( i ); }
+			inline handle_type _get_handle( index_type i ) const { return m_index.get_handle( i ); }
 
 			inline const value_type& operator[] ( index_type i ) const { return m_data[i]; }
@@ -157,13 +155,14 @@
 			inline iterator        begin() { return m_data.begin(); }
 			inline const_iterator  begin()  const { return m_data.begin(); }
-			inline const_iterator  cbegin() const { return m_data.begin(); }
 
 			inline iterator        end() { return m_data.end(); }
 			inline const_iterator  end()  const { return m_data.end(); }
-			inline const_iterator  cend() const { return m_data.end(); }
+
+			//inline virtual component_storage* storage() { return &m_data; }
 		protected:
 			ecs_type&        m_ecs;
+			storage_type     m_data;
+		private:
 			index_table_type m_index;
-			storage_type     m_data;
 		};
 
Index: trunk/nv/ecs/component_storage.hh
===================================================================
--- trunk/nv/ecs/component_storage.hh	(revision 541)
+++ trunk/nv/ecs/component_storage.hh	(revision 542)
@@ -25,4 +25,135 @@
 	namespace ecs
 	{
+
+		class component_storage
+		{
+		protected:
+			component_storage() {}
+			template < typename T >
+			void initialize()
+			{
+				m_data = nullptr;
+				m_size = 0;
+				m_allocated = 0;
+				// TODO: detect trivially destructible objects
+				m_destructor = raw_destroy_object < T >;
+				m_csize = sizeof( T );
+			}
+		public:
+			void reserve( uint32 count )
+			{
+				reallocate( count );
+			}
+			uint32 size() const { return m_size; }
+			uint32 raw_size() const { return m_size * m_csize; }
+			void reset()
+			{
+				clear();
+				nvfree( m_data );
+				m_data = nullptr;
+				m_allocated = 0;
+			}
+			void clear()
+			{
+				uint32 count = m_size;
+				uint8* d     = m_data;
+				for ( ; count > 0; --count, d += m_csize )
+					m_destructor(d);
+				m_size = 0;
+			}
+			void* raw() { return m_data; }
+			const void* raw() const { return m_data; }
+			// TODO: Debug-time type checking
+			template < typename T >
+			T* as() { return (T*)m_data; }
+			template < typename T >
+			const T* as() const { return m_data; }
+
+			void pop_back()
+			{
+				NV_ASSERT( m_size > 0, "BAD OP!" );
+				m_size--;
+				m_destructor( m_data + m_size * m_csize );
+			}
+
+			~component_storage()
+			{
+				reset();
+			}
+		protected:
+			void grow()
+			{
+				uint32 new_size = m_size + 1;
+				if ( new_size > m_allocated )
+				{
+					reallocate( m_allocated > 3 ? m_allocated * 2 : 8 );
+				}
+				m_size = new_size;
+			}
+
+			void reallocate( uint32 new_size )
+			{
+				m_data = static_cast<uint8*>( nvrealloc( m_data, new_size * m_csize ) );
+				m_allocated = new_size;
+				NV_ASSERT( m_data, "OMG" );
+			}
+
+			//thash64 m_type;
+			uint32       m_csize;
+			uint32       m_allocated;
+			uint32       m_size;
+			destructor_t m_destructor;
+			uint8*       m_data;
+		};
+
+		template < typename Component >
+		class component_storage_handler : public component_storage
+		{
+		public:
+			typedef Component         value_type;
+			typedef Component*        iterator;
+			typedef const Component*  const_iterator;
+			typedef Component&        reference;
+			typedef const Component&  const_reference;
+
+			component_storage_handler() 
+			{
+				initialize<Component>();
+			}
+			Component* data() { return (Component*)m_data; }
+			const Component* data() const { return (Component*)m_data; }
+			inline const Component& operator[] ( uint32 i ) const { return ((Component*)m_data)[i]; }
+			inline Component& operator[] ( uint32 i ) { return ( (Component*)m_data )[i]; }
+
+			inline iterator        begin() { return (Component*)m_data; }
+			inline const_iterator  begin()  const { return (const Component*)m_data; }
+			inline void*           raw_begin() { return m_data; }
+			inline const void*     raw_begin() const { return m_data; }
+
+			inline iterator        end() { return ((Component*)m_data)+m_size; }
+			inline const_iterator  end()  const { return ( (Component*)m_data ) + m_size; }
+			inline void*           raw_end() { return ( (Component*)m_data ) + m_size; }
+			inline const void*     raw_end() const { return ( (Component*)m_data ) + m_size; }
+
+			template < typename... Args >
+			void emplace_back( Args&&... args )
+			{
+				grow();
+				construct_object( data() + sint32( m_size ) - 1, forward<Args>( args )... );
+			}
+
+			Component& back()
+			{
+				NV_ASSERT( m_size > 0, "EMPTY COMPONENT STORAGE" );
+				return *( data() + sint32( m_size ) - 1 );
+			}
+		};
+
+		template < typename Component >
+		component_storage_handler< Component >* storage_cast( component_storage* storage )
+		{
+			// TODO: error checking
+			return ( component_storage_handler< Component >* )storage;
+		}
 
 		template < typename Handle, typename Component >
Index: trunk/nv/ecs/ecs.hh
===================================================================
--- trunk/nv/ecs/ecs.hh	(revision 541)
+++ trunk/nv/ecs/ecs.hh	(revision 542)
@@ -23,4 +23,6 @@
 #include <nv/core/types.hh>
 #include <nv/ecs/message_queue.hh>
+#include <nv/ecs/component_storage.hh>
+
 
 namespace nv
@@ -34,23 +36,37 @@
 	namespace ecs
 	{
-
-		template < typename Handle, typename Time = f32 >
-		class ecs : public message_queue< Handle, Time >
+		template < typename S, typename C, typename M >
+		using has_component_message = detail::has_message<S, void( const M&, C& ) >;
+
+		template < typename E, typename S, typename C, typename M >
+		using has_ecs_component_message = detail::has_message<S, void( const M&, E&, C& ) >;
+
+		template < typename E, typename S, typename M >
+		using has_ecs_message = detail::has_message<S, void( const M&, E& ) >;
+
+
+		template < typename Handle, typename MessageList, typename Time = f32 >
+		class ecs : public message_queue< MessageList, Time >
 		{
 		public:
-			typedef message_queue< Handle, Time > base_class;
-			using base_class::time_type;
-			using base_class::handle_type;
-			using base_class::message_type;
-			using base_class::message;
-			using base_class::receiver_interface;
-
-			class component_interface : public receiver_interface
+			typedef message_queue< MessageList, Time > base_type;
+			typedef ecs< Handle, MessageList, Time >   this_type;
+			typedef Handle                             handle_type;
+			using base_type::time_type;
+			using base_type::message_type;
+			using base_type::message;
+
+
+
+			class component_interface
 			{
 			public:
+				virtual void update( time_type dtime ) = 0;
+				virtual void clear() = 0;
 				virtual void initialize( handle_type, lua::stack_proxy& ) = 0;
 				virtual void remove( handle_type h ) = 0;
 				virtual void* get_raw( handle_type h ) = 0;
 				virtual const void* get_raw( handle_type h ) const = 0;
+//				virtual component_storage* storage() = 0;
 			};
 
@@ -65,21 +81,76 @@
 					return *this;
 				}
-				value_enumerator_base operator++ ( int )
-				{
-					auto result = *this;
-					base_class::m_value = m_ecs.next( base_class::m_value );
-					return result;
-				}
+// 				enumerator operator++ ( int )
+// 				{
+// 					auto result = *this;
+// 					base_class::m_value = m_ecs.next( base_class::m_value );
+// 					return result;
+// 				}
 			private:
 				const ecs& m_ecs;
 			};
 
-			template < typename Component >
+			template< typename Component > 
+			class component_enumerator : public iterator< input_iterator_tag, Component >
+			{
+			public:
+				typedef value_enumerator_base < handle_type > base_class;
+				explicit component_enumerator( ecs& aecs, handle_type current = handle_type() )
+					: m_ecs( aecs ), m_handle( current ), m_component( nullptr )
+				{
+					m_interface = m_ecs.get_interface< Component >();
+					if ( m_interface && m_handle )
+					{
+						m_component = (Component*)m_interface->get_raw( current );
+						if ( !m_component )
+							find_next();
+					}
+					else
+						m_handle = handle_type();
+				}
+				component_enumerator& operator++ ()
+				{
+					find_next();
+					return *this;
+				}
+				Component& operator* () { return *m_component; }
+				Component* operator-> () { return &m_component; }
+				const Component& operator* () const { return *m_component; }
+				const Component* operator-> () const { return &m_component; }
+				bool operator== ( const component_enumerator& rhs ) const
+				{
+					return m_handle == rhs.m_handle;
+				}
+				bool operator!= ( const component_enumerator& rhs ) const
+				{
+					return !( *this == rhs );
+				}
+			private:
+				void find_next()
+				{
+					if ( !m_interface ) return;
+					do {
+						m_handle = m_ecs.next( m_handle );
+						m_component = (Component*)m_interface->get_raw( m_handle );
+					} while ( m_handle && !m_component );
+				}
+				component_interface* m_interface;
+				handle_type m_handle;
+				Component* m_component;
+				ecs& m_ecs;
+			};
+
+			template < typename Component, typename Handler >
 			void register_component( string_view name, component_interface* c )
 			{
 				m_components.push_back( c );
-				register_receiver( name, c );
 				m_component_map[thash64::create<Component>()] = c;
 				m_component_map_by_name[name] = c;
+				register_handler< Handler >( name, (Handler*)c );
+				register_component_messages< Handler, Component >( (Handler*)( c ), message_list{} );
+//				auto s = c->storage();
+// 				m_cstorage.push_back( s );
+// 				m_cmap[thash64::create<Component>()] = s;
+// 				m_cmap_by_name[name] = s;
 			}
 
@@ -89,10 +160,25 @@
 			}
 
+			void update( time_type dtime )
+			{
+				update_time( dtime );
+				for ( auto c : m_components )
+					c->update( dtime );
+			}
+
 			void clear()
 			{
 				reset_events();
-				for ( auto c : m_receivers )
+				for ( auto c : m_components )
 					c->clear();
 				m_handles.clear();
+			}
+
+			~ecs()
+			{
+// 				for ( auto cs : m_component_storage )
+// 					delete cs;
+//				m_cstorage.clear();
+
 			}
 
@@ -126,4 +212,13 @@
 			}
 
+			template< typename Component >
+			enumerator_provider< component_enumerator< Component > > child_components( handle_type h )
+			{
+				return enumerator_provider< component_enumerator< Component > >(
+					component_enumerator< Component >( *this, first_child( h ) ),
+					component_enumerator< Component >( *this )
+					);
+			}
+
 			void remove( handle_type h )
 			{
@@ -157,7 +252,19 @@
 
 			template < typename Component >
+			component_interface* get_interface()
+			{
+				return m_component_map[thash64::create< Component >()];
+			}
+
+			template < typename Component >
+			const component_interface* get_interface() const
+			{
+				return m_component_map[thash64::create< Component >()];
+			}
+
+			template < typename Component >
 			Component* get( handle_type h )
 			{
-				return static_cast< Component* >( m_component_map[thash64::create< Component >()]->get_raw( h ) );
+				return static_cast<Component*>( m_component_map[thash64::create< Component >()]->get_raw( h ) );
 			}
 
@@ -168,5 +275,79 @@
 			}
 
+			template < typename Component >
+			typename component_storage_handler< Component >*
+			get_storage()
+			{
+				return storage_cast< Component >( m_cmap[thash64::create< Component >()] );
+			}
+
+			template < typename Component >
+			const typename component_storage_handler< Component >*
+			get_storage() const
+			{
+				return storage_cast< Component >( m_cmap[thash64::create< Component >()] );
+			}
+
 		protected:
+
+			template < typename System, typename Components, template <class...> class List, typename... Messages >
+			void register_component_messages( System* h, List<Messages...>&& )
+			{
+				int unused_0[] = { ( register_component_message<System,Components,Messages>( h ), 0 )... };
+				int unused_1[] = { ( register_ecs_component_message<System,Components,Messages>( h ), 0 )... };
+				int unused_2[] = { ( register_ecs_message<System,Messages>( h ), 0 )... };
+			}
+
+			template < typename System, typename Components, typename Message >
+			typename enable_if< has_component_message< System, Components, Message >::value, void >::type
+			register_component_message( System* s )
+			{
+				component_interface* ci = get_interface<Components>();
+ 				register_callback( Message::message_id, [=] ( const message& msg )
+ 				{
+					const Message& m = message_cast<Message>( msg );
+					if ( void* c = ci->get_raw( m.entity ) )
+						s->on( m, *((Components*)(c)) );
+ 				} );
+
+			}
+
+			template < typename System, typename Components, typename Message >
+			typename enable_if< has_ecs_component_message< this_type, System, Components, Message >::value, void >::type
+			register_ecs_component_message( System* s )
+			{
+				component_interface* ci = get_interface<Components>();
+ 				register_callback( Message::message_id, [=] ( const message& msg )
+ 				{
+					const Message& m = message_cast<Message>( msg );
+					if ( void* c = ci->get_raw( m.entity ) )
+						s->on( m, *this, *((Components*)(c)) );
+ 				} );
+
+			}
+			template < typename System, typename Message >
+			typename enable_if< has_ecs_message< this_type, System, Message >::value, void >::type
+			register_ecs_message( System* s )
+			{
+ 				register_callback( Message::message_id, [=] ( const message& msg )
+ 				{
+					s->on( message_cast<Message>( msg ), *this );
+ 				} );
+
+			}
+
+			template < typename System, typename Components, typename Message >
+			typename enable_if< !has_component_message< System, Components, Message >::value, void >::type
+			register_component_message( System* ) {}
+
+			template < typename System, typename Components, typename Message >
+			typename enable_if< !has_ecs_component_message< this_type, System, Components, Message >::value, void >::type
+			register_ecs_component_message( System* ) {}
+
+			template < typename System, typename Message >
+			typename enable_if< !has_ecs_message< this_type, System, Message >::value, void >::type
+			register_ecs_message( System* ) {}
+
+
 
 			handle_tree_manager< handle_type >          m_handles;
@@ -174,4 +355,7 @@
 			hash_store< thash64, component_interface* > m_component_map;
 			hash_store< shash64, component_interface* > m_component_map_by_name;
+// 			vector< component_storage* >                m_cstorage;
+// 			hash_store< thash64, component_storage* >   m_cmap;
+// 			hash_store< shash64, component_storage* >   m_cmap_by_name;
 		};
 
Index: trunk/nv/ecs/message_queue.hh
===================================================================
--- trunk/nv/ecs/message_queue.hh	(revision 541)
+++ trunk/nv/ecs/message_queue.hh	(revision 542)
@@ -18,4 +18,6 @@
 #include <nv/stl/handle.hh>
 #include <nv/stl/priority_queue.hh>
+#include <nv/stl/mpl/list.hh>
+#include <nv/stl/functional/function.hh>
 #include <nv/core/types.hh>
 
@@ -25,4 +27,33 @@
 	namespace ecs
 	{
+
+		namespace detail
+		{
+			template<typename, typename T>
+			struct has_message
+			{
+				static_assert( nv::integral_constant<T, false>::value, "Second template parameter needs to be of function type." );
+			};
+
+			template< typename C, typename Ret, typename... Args >
+			struct has_message<C, Ret( Args... )>
+			{
+			private:
+				template<typename T>
+				static constexpr auto check( T* )
+					-> typename nv::is_same< decltype( nv::declval<T>().on( nv::declval<Args>()... ) ), Ret >::type;
+
+				template<typename>
+				static constexpr nv::false_type check( ... );
+
+				typedef decltype( check<C>( 0 ) ) type;
+
+			public:
+				static constexpr bool value = type::value;
+			};
+		}
+
+		template < typename S, typename M >
+		using has_message = detail::has_message<S, void( const M& ) >;
 
 		template < typename Payload, typename Message >
@@ -35,18 +66,24 @@
 
 
-		template < typename Handle, typename Time = f32 >
+		template < typename MessageList, typename Time = f32 >
 		class message_queue
 		{
 		public:
-			typedef Time   time_type;
-			typedef Handle handle_type;
-			typedef uint32 message_type;
-
-			struct message
+			typedef Time        time_type;
+			typedef MessageList message_list;
+			typedef uint32      message_type;
+
+			constexpr static const uint32 message_list_size = mpl::list_size< message_list >::value;
+
+			message_queue()
+			{
+				m_handlers.resize( message_list_size );
+			}
+
+			struct message 
 			{
 				message_type type;
-				handle_type  entity;
 				time_type    time;
-				uint8        payload[128 - sizeof( uint32 ) - sizeof( handle_type ) - sizeof( time_type )];
+				uint8        payload[128 - sizeof( message_type ) - sizeof( time_type ) ];
 			};
 
@@ -59,30 +96,35 @@
 			};
 
+			using message_handler = function< void( const message& ) >;
+				
+			struct message_handlers
+			{
+				vector< message_handler > list;
+			};
+
 			typedef priority_queue< message, vector< message >, message_compare_type > queue_type;
 
-			class receiver_interface
-			{
-			public:
-				virtual void update( time_type dtime ) = 0;
-				virtual bool handle_message( const message& ) = 0;
-				virtual void clear() = 0;
-			};
-
-			void register_receiver( string_view /*name*/, receiver_interface* c )
-			{
-				m_receivers.push_back( c );
+			template< typename Handler >
+			void register_handler( string_view /*name*/, Handler* c )
+			{
+				register_messages< Handler > ( (Handler*)( c ), message_list{} );
+			}
+
+			template<>
+			void register_handler<void>( string_view /*name*/, void* )
+			{
 			}
 
 			bool dispatch( const message& m )
 			{
-				for ( auto c : m_receivers )
-					c->handle_message( m );
+				for ( auto& h : m_handlers[m.type].list )
+					h( m );
 				return true;
 			}
 
 			template < typename Payload, typename ...Args >
-			bool dispatch( handle_type h, Args&&... args )
-			{
-				message m{ Payload::message_id, h, time_type( 0 ) };
+			bool dispatch( Args&&... args )
+			{
+				message m{ Payload::message_id, time_type( 0 ) };
 				new( &m.payload ) Payload{ nv::forward<Args>( args )... };
 				return dispatch( m );
@@ -96,7 +138,7 @@
 
 			template < typename Payload, typename ...Args >
-			bool queue( handle_type h, time_type delay, Args&&... args )
-			{
-				message m{ Payload::message_id, h, m_time + delay };
+			bool queue( time_type delay, Args&&... args )
+			{
+				message m{ Payload::message_id, m_time + delay };
 				new( &m.payload ) Payload{ nv::forward<Args>( args )... };
 				return queue( m );
@@ -121,5 +163,5 @@
 			}
 
-			void update( time_type dtime )
+			void update_time( time_type dtime )
 			{
 				if ( dtime == time_type( 0 ) ) return;
@@ -131,12 +173,8 @@
 					dispatch( msg );
 				}
-
-				for ( auto c : m_receivers )
-					c->update( dtime );
 			}
 
 			time_type update_step()
 			{
-				time_type before = m_time;
 				if ( !m_pqueue.empty() )
 				{
@@ -145,47 +183,41 @@
 					m_pqueue.pop();
 					dispatch( msg );
-					if ( before != m_time )
-						for ( auto c : m_receivers )
-							c->update( m_time - before );
 				}
 				return m_time;
 			}
 
+			void register_callback( message_type msg, message_handler&& handler )
+			{
+				m_handlers[msg].list.push_back( handler );
+			}
+
 		protected:
+
+			template < typename System, template <class...> class List, typename... Messages >
+			void register_messages( System* h, List<Messages...>&& )
+			{
+				int unused[] = { ( register_message<System,Messages>( h ), 0 )... };
+			}
+
+
+			template < typename System, typename Message >
+			typename enable_if< has_message< System, Message >::value, void >::type
+			register_message( System* s )
+			{
+				register_callback( Message::message_id, [=] ( const message& msg )
+				{
+					s->on( message_cast<Message>( msg ) );
+				} );
+			}
+
+			template < typename System, typename Message >
+			typename enable_if< !has_message< System, Message >::value, void >::type
+			register_message( System* ) {}
+
 			time_type                     m_time = time_type( 0 );
 			queue_type                    m_pqueue;
-			vector< receiver_interface* > m_receivers;
+			vector< message_handlers >    m_handlers;
 		};
 
-		template < typename Ecs >
-		class receiver : public Ecs::receiver_interface
-		{
-		public:
-			typedef Ecs                                    ecs_type;
-			typedef typename ecs_type::message             message_type;
-			typedef typename ecs_type::handle_type         handle_type;
-			typedef typename ecs_type::time_type           time_type;
-
-			receiver( ecs_type& a_ecs, string_view a_name ) : m_ecs( a_ecs )
-			{
-				m_ecs.register_receiver( a_name, this );
-			}
-			virtual void update( time_type /*dtime*/ )
-			{
-				// no-op
-			}
-
-			virtual void clear()
-			{
-				// no-op
-			}
-			virtual bool handle_message( const message_type& )
-			{
-				return false;
-			}
-		protected:
-			ecs_type&        m_ecs;
-		};
-
 	}
 
Index: trunk/nv/stl/algorithm/copy.hh
===================================================================
--- trunk/nv/stl/algorithm/copy.hh	(revision 541)
+++ trunk/nv/stl/algorithm/copy.hh	(revision 542)
@@ -41,5 +41,5 @@
 		inline OutputIterator copy_n_impl( InputIterator first, size_t n, OutputIterator out, AnyType, input_iterator_tag, forward_iterator_tag )
 		{
-			for ( ; n-- > 0; ++first, ++out ) *first = *out;
+			for ( ; n-- > 0; ++first, ++out ) *out = *first++;
 			return out;
 		}
Index: trunk/nv/stl/index_table.hh
===================================================================
--- trunk/nv/stl/index_table.hh	(revision 541)
+++ trunk/nv/stl/index_table.hh	(revision 542)
@@ -75,18 +75,18 @@
 		}
 
-		index_type remove_swap( index_type dead_eindex )
-		{
-			if ( uint32( dead_eindex ) >= m_handles.size() ) return -1;
-			handle_type h = m_handles[dead_eindex];
-			handle_type swap_handle = m_handles.back();
-			if ( dead_eindex != static_cast<index_type>( m_handles.size() - 1 ) )
-			{
-				m_handles[unsigned( dead_eindex )] = swap_handle;
-				m_indexes[swap_handle.index()] = dead_eindex;
-			}
-			m_handles.pop_back();
-			m_indexes[h.index()] = -1;
-			return dead_eindex;
-		}
+// 		index_type remove_swap( index_type dead_eindex )
+// 		{
+// 			if ( uint32( dead_eindex ) >= m_handles.size() ) return -1;
+// 			handle_type h = m_handles[dead_eindex];
+// 			handle_type swap_handle = m_handles.back();
+// 			if ( dead_eindex != static_cast<index_type>( m_handles.size() - 1 ) )
+// 			{
+// 				m_handles[unsigned( dead_eindex )] = swap_handle;
+// 				m_indexes[swap_handle.index()] = dead_eindex;
+// 			}
+// 			m_handles.pop_back();
+// 			m_indexes[h.index()] = -1;
+// 			return dead_eindex;
+// 		}
 
 
@@ -159,5 +159,5 @@
 			if ( h.is_nil() ) return -1;
 			auto ih = m_indexes.find( h );
-			if ( ih == m_indexes.end() ) return -1;
+			if ( ih == m_indexes.end() || ih->second == index_type(-1) ) return -1;
 			handle_type swap_handle = m_handles.back();
 			index_type  dead_eindex = ih->second;
