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


C++ vector::base方法代码示例

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


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

示例1: add

    // adds a value, returning false if the given token is not
    // "reasonable".  A reasonable token is one not currently in use,
    // and if any previously used tokens are available, it must be one
    // of the previously used ones.  If no previously used tokens are
    // available, it must be the smallest unused token.  You'll get
    // good performance if you never choose a bad token and use the
    // most recently dropped token.
    bool add(token_type known_token, T const& value) {
        if (free_.empty()) {
            if (known_token == values_.size()) {
                values_.push_back(value);
#ifndef NDEBUG
                is_free_.push_back(false);
#endif
                return true;
            } else {
                return false;
            }
        } else {
            // If a replicand used add(), then it picked the token
            // from the bock of its free list.  So the replicant, the
            // presumed caller of this function, searches in reverse
            // order.
            typename std::vector<token_t>::reverse_iterator p = std::find(free_.rbegin(), free_.rend(), known_token);
            if (p == free_.rend()) {
                return false;
            }

            if (values_.size() > known_token) {
                free_.erase(p.base() - 1);
                values_[known_token] = value;
                rassert(is_free_[known_token]);
#ifndef NDEBUG
                is_free_[known_token] = false;
#endif

                return true;
            } else {
                return false;
            }
        }
    }
开发者ID:AVGP,项目名称:rethinkdb,代码行数:42,代码来源:thick_list.hpp


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