stack.mh

来自「开放源码的编译器open watcom 1.6.0版的源代码」· MH 代码 · 共 95 行

MH
95
字号
///////////////////////////////////////////////////////////////////////////
// FILE: stack ()
//
:keep CPP_HDR
:include crwatcnt.sp
//
// Description: This header is part of the C++ standard library.
//              It defines the std::stack template adaptor
///////////////////////////////////////////////////////////////////////////
#ifndef _STACK_INCLUDED
#define _STACK_INCLUDED

:include readonly.sp

#ifndef __cplusplus
#error The header stack requires C++
#endif

#ifndef _VECTOR_INCLUDED
    #include <vector>
#endif

namespace std {
/*===================================================================
 * stack template adaptor
 */
//standard says the following should be class Container = deque< Type > 
//deque hasn't been written yet
template< class Type, class Container = vector< Type > >
class stack{
public:
    typedef typename Container::value_type  value_type;
    typedef typename Container::size_type   size_type;
    typedef          Container              container_type;
protected:
    Container c;
public:
    explicit            stack( Container const & x = Container() ) : c( x ) {}
    bool                empty() const   { return( c.empty() ); }
    size_type           size()  const   { return( c.size() ); }
    value_type&         top()           { return( c.back() ); }
    value_type const &  top() const     { return( c.back() ); }
    void                push( value_type const & v )
                                        { c.push_back( v ); }
    void                pop()           { c.pop_back(); }
    
    bool                _Sane()         { return( c._Sane() ); }
};

template< class Type, class Container>
bool operator==( stack< Type, Container > const & x,
                 stack< Type, Container > const & y )
{
    return( x.c == y.c );
}

template< class Type, class Container>
bool operator!=( stack< Type, Container > const & x,
                 stack< Type, Container > const & y )
{
    return( x.c != y.c );
}

template< class Type, class Container>
bool operator<( stack< Type, Container > const & x,
                stack< Type, Container > const & y )
{
    return( x.c < y.c );
}

template< class Type, class Container>
bool operator>( stack< Type, Container > const & x,
                stack< Type, Container > const & y )
{
    return( x.c > y.c );
}

template< class Type, class Container>
bool operator>=( stack< Type, Container > const & x,
                 stack< Type, Container > const & y )
{
    return( x.c >= y.c );
}

template< class Type, class Container>
bool operator<=( stack< Type, Container > const & x,
                 stack< Type, Container > const & y )
{
    return( x.c <= y.c );
}

} // End of namespace std.

#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?