zoukankan      html  css  js  c++  java
  • STL 之 stack 源代码剖析

    G++ 2.91.57,cygnuscygwin-b20includeg++stl_stack.h 完整列表
    /*
     *
     * Copyright (c) 1994
     * Hewlett-Packard Company
     *
     * Permission to use, copy, modify, distribute and sell this software
     * and its documentation for any purpose is hereby granted without fee,
     * provided that the above copyright notice appear in all copies and
     * that both that copyright notice and this permission notice appear
     * in supporting documentation.  Hewlett-Packard Company makes no
     * representations about the suitability of this software for any
     * purpose.  It is provided "as is" without express or implied warranty.
     *
     *
     * Copyright (c) 1996,1997
     * Silicon Graphics Computer Systems, Inc.
     *
     * Permission to use, copy, modify, distribute and sell this software
     * and its documentation for any purpose is hereby granted without fee,
     * provided that the above copyright notice appear in all copies and
     * that both that copyright notice and this permission notice appear
     * in supporting documentation.  Silicon Graphics makes no
     * representations about the suitability of this software for any
     * purpose.  It is provided "as is" without express or implied warranty.
     */
    
    /* NOTE: This is an internal header file, included by other STL headers.
     *   You should not attempt to use it directly.
     */
    
    #ifndef __SGI_STL_INTERNAL_STACK_H
    #define __SGI_STL_INTERNAL_STACK_H
    
    __STL_BEGIN_NAMESPACE
    
    #ifndef __STL_LIMITED_DEFAULT_TEMPLATES
    template <class T, class Sequence = deque<T> >
    #else
    template <class T, class Sequence>
    #endif
    class stack {
      friend bool operator== __STL_NULL_TMPL_ARGS (const stack&, const stack&);
      friend bool operator< __STL_NULL_TMPL_ARGS (const stack&, const stack&);
    public:
      typedef typename Sequence::value_type value_type;
      typedef typename Sequence::size_type size_type;
      typedef typename Sequence::reference reference;
      typedef typename Sequence::const_reference const_reference;
    protected:
      Sequence c;	// 底層容器
    public:
      // 下面全然利用 Sequence c 的操作。完毕 stack 的操作。
      bool empty() const { return c.empty(); }
      size_type size() const { return c.size(); }
      reference top() { return c.back(); }
      const_reference top() const { return c.back(); }
      // deque 是兩頭可進出,stack 是末端進,末端出(所以後進者先出)。
      void push(const value_type& x) { c.push_back(x); }
      void pop() { c.pop_back(); }
    };
    
    template <class T, class Sequence>
    bool operator==(const stack<T, Sequence>& x, const stack<T, Sequence>& y) {
      return x.c == y.c;
    }
    
    template <class T, class Sequence>
    bool operator<(const stack<T, Sequence>& x, const stack<T, Sequence>& y) {
      return x.c < y.c;
    }
    
    __STL_END_NAMESPACE
    
    #endif /* __SGI_STL_INTERNAL_STACK_H */
    
    // Local Variables:
    // mode:C++
    // End:
    

  • 相关阅读:
    测试心得---杂七杂八
    Redis 集群缓存测试要点--关于 线上 token 失效 BUG 的总结
    linux基础
    如何获取新系统的业务逻辑?
    python笔记9-多线程Threading之阻塞(join)和守护线程(setDaemon)
    python笔记8-多线程threading之封装式
    redis监控key失效
    使用PageHepler分页
    使用token和redis怎样判断账户是否失效和异地登录
    JSONObject
  • 原文地址:https://www.cnblogs.com/mqxnongmin/p/10878005.html
Copyright © 2011-2022 走看看