/* * Copyright (c) 2017 Jaroslav Jindrak * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef LIBCPP_STACK #define LIBCPP_STACK #include #include #include namespace std { /** * 23.5.6.2, stack: */ // TODO: the default container should be deque template> class stack { public: using container_type = Container; using value_type = typename container_type::value_type; using reference = typename container_type::reference; using const_reference = typename container_type::const_reference; using size_type = typename container_type::size_type; explicit stack(container_type& cont) : c{cont} { /* DUMMY BODY */ } explicit stack(container_type&& cont = container_type{}) : c{move(cont)} { /* DUMMY BODY */ } /** * TODO: The allocator constructor should use enable_if * as a last parameter that checks if uses_allocator * from holds. */ template explicit stack(Alloc& alloc) : c{alloc} { /* DUMMY BODY */ } template stack(const container_type& cont, const Alloc& alloc) : c{cont, alloc} { /* DUMMY BODY */ } template stack(container_type&& cont, const Alloc& alloc) : c{move(cont), alloc} { /* DUMMY BODY */ } template stack(const stack& other, const Alloc& alloc) : c{other.c, alloc} { /* DUMMY BODY */ } template stack(stack&& other, const Alloc& alloc) : c{move(other.c), alloc} { /* DUMMY BODY */ } bool empty() { return c.empty(); } size_type size() { return c.size(); } reference top() { return c.back(); } const_reference top() const { return c.back(); } void push(const value_type& val) { c.push_back(val); } void push(value_type&& val) { c.push_back(move(val)); } template void emplace(Args&&... args) { c.emplace_back(forward(args)...); } void pop() { c.pop_back(); } void swap(stack& other) /* noexcept(noexcept(swap(c, other.c))) */ { std::swap(c, other.c); } protected: container_type c; }; /** * 23.6.5.5, stack operators: */ template bool operator==(const stack& lhs, const stack& rhs) { return lhs.c == rhs.c; } template bool operator!=(const stack& lhs, const stack& rhs) { return lhs.c != rhs.c; } template bool operator<(const stack& lhs, const stack& rhs) { return lhs.c < rhs.c; } template bool operator<=(const stack& lhs, const stack& rhs) { return lhs.c <= rhs.c; } template bool operator>(const stack& lhs, const stack& rhs) { return lhs.c > rhs.c; } template bool operator>=(const stack& lhs, const stack& rhs) { return lhs.c >= rhs.c; } /** * 23.6.5.6, stack specialized algorithms: */ template void swap(stack& lhs, stack& rhs) noexcept(noexcept(lhs.swap(rhs))) { lhs.swap(rhs); } } #endif