当前位置: 首页>>代码示例>>C++>>正文


C++ std::_Destroy方法代码示例

本文整理汇总了C++中std::_Destroy方法的典型用法代码示例。如果您正苦于以下问题:C++ std::_Destroy方法的具体用法?C++ std::_Destroy怎么用?C++ std::_Destroy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std的用法示例。


在下文中一共展示了std::_Destroy方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: clear

 void clear()
 {
     // Call the destructor for all objects and reinitialize the memory.
     _Destroy( begin(), end() );
     initialize_memory();
     m_num_elements = 0;
 }
开发者ID:unitsea-developer,项目名称:ET4QA,代码行数:7,代码来源:cache_table.hpp

示例2:

    value_type& find_or_insert( const key_type& key )
    {
        size_t buck = m_hasher( key ) & m_mask;
        key_type& table_key = m_key_extract( m_table[ buck ] );
        
        if ( ! m_key_equal( key, table_key ) )
        {            
            // The bucket is either empty or it contains another item.  In
            // this case we have to mark it as discarded, because we cannot
            // know how the reference will be used ( probably to overwrite
            // the item with a new one that has a different key ).
            if ( ! m_key_equal( table_key, m_empty_key ) )
            {
                // The bucket already contained an item. This item is
                // discarded and replaced with an empty one. The destructor
                // is called on it.
                // The m_num_elements does not change because 
                m_discard( m_table[ buck ], m_empty_value );
                _Destroy( m_table + buck );
                reset_value( m_table + buck );
            }
            else
            {
                // The bucket was empty, so we have to increment the items
                // counter
                ++m_num_elements;
            }

            // Set the key in the empty item
            _Construct( &table_key, key );
        }

        // Returns the reference to the found or recently added item
        return m_table[ buck ];
    }
开发者ID:unitsea-developer,项目名称:ET4QA,代码行数:35,代码来源:cache_table.hpp

示例3: insert

    pair<iterator,bool> insert( const value_type& obj )
    {
        const key_type& obj_key = m_key_extract( obj );
        const size_t buck = m_hasher( obj_key ) & m_mask;
            
        const key_type& table_key = m_key_extract( m_table[ buck ] );
        
        if ( ! m_key_equal( table_key, m_empty_key ) )
        {
            // There's already an item in the bucket and its key it different
            // from the key of the inserted item.  Element is discarded.
            ++m_num_collisions;

            // Notify that the item will be discarded, to allow a policy to
            // do something useful with it.
            m_discard( m_table[ buck ], obj );
            _Destroy( m_table + buck );
            reset_value( m_table + buck );
        }
        else
            ++m_num_elements;

        // Copy the object into the hash table.
        _Construct( m_table + buck, obj );
        return pair<iterator,bool>( iterator( this, m_table + buck ), true );
    }
开发者ID:unitsea-developer,项目名称:ET4QA,代码行数:26,代码来源:cache_table.hpp

示例4: erase

 void erase( const iterator& it )
 {
     if (    it != m_end_it
          && ! m_key_equal( m_key_extract( *it ), m_empty_key ) )
     {
         _Destroy( &* it );
         reset_value( it.m_pos );
         --m_num_elements;
     }
 }
开发者ID:unitsea-developer,项目名称:ET4QA,代码行数:10,代码来源:cache_table.hpp

示例5: resize

    void resize( size_type size )
    {
        size_t new_size = round_to_power2( size );
        size_t old_size = m_buckets;

        if ( new_size == old_size )
        {
            // Do nothing
            return;
        }
        else if ( new_size < old_size )
        {
            // The new table will be smaller, so there's no need to rehash
            // all the items.
            value_type* new_table;
            new_table = m_allocator.allocate( new_size * ItemSize );

            // Copy the elements that fit into the new table and destroy
            // those that doesn't fit.  Plain old memcpy seems to have much
            // less problems with types than std::copy..
            std::memcpy( new_table, m_table, new_size * ItemSize );
            _Destroy( iterator( this, m_table + new_size, true ), m_end_it );

            m_allocator.deallocate( m_table, old_size );
            m_table = new_table;
            
            m_end_marker = m_table + new_size;
            m_end_it = iterator( this, m_end_marker );
            m_buckets = new_size;
            m_mask = m_buckets - 1;

            // Re-count the number of elements.
            m_num_elements = 0;
            for ( const_iterator it = begin(); it != m_end_it; ++it )
                ++m_num_elements;
        }
        else // new_size > old_size
        {
            // Creates a new table and re-insert all the items, with
            // new buckets.
            cache_table other( new_size, m_hasher, m_key_equal );
            other.set_empty_value( m_empty_value );
            swap( other );
            insert( other.begin(), other.end() );
        }
    }
开发者ID:unitsea-developer,项目名称:ET4QA,代码行数:46,代码来源:cache_table.hpp


注:本文中的std::_Destroy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。