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


C++ policy_type::insert方法代码示例

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


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

示例1: insert

        /*!
         * \brief Insert element to the cache
         *
         * The cache is extended by inserting a single new element. This effectively increases the cache size. Because cache do not allow for duplicate key values, the insertion operation checks for each element inserted whether another element exists already in the container with the same key value, if so, the element is not inserted and its mapped value is not changed in any way.
         * Extension of cache could result in removal of some elements, depending of the cache fullness and used policy. It is also possible, that removal of excessive entries
         * will fail, therefore insert operation will fail too.
         *
         * \throw <exception_cache_full>  Thrown when there are no available space in the cache and policy doesn't allows removal of elements.
         * \throw <exception_invalid_key> Thrown when the policy doesn't accepts the key
         *
         * \return true if the new elemented was inserted or false if an element with the same key existed.
         */
        bool insert(Key _k, Data _d) {
            write_lock_type l = lock.lockWrite();
            while (this->_currEntries >= this->_maxEntries) {
                _victim<Key> victim=_policy->victim();
                if (!victim) {
                    throw exception_cache_full("The cache is full and no element can be expired at the moment. Remove some elements manually");
                }
                this->_erase(*victim);
            }

            _policy->insert(_k);


            bool result=_storage.insert(value_type(_k,_d)).second;
            if (result) {
                _currEntries++;
            }

            return result;
        }
开发者ID:akashihi,项目名称:stlcache,代码行数:32,代码来源:stlcache.hpp


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