Changeset 23dcc14 in mainline


Ignore:
Timestamp:
2018-07-05T21:41:22Z (6 years ago)
Author:
Dzejrou <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f9823e2
Parents:
3f7031a
git-author:
Dzejrou <dzejrou@…> (2018-04-27 15:33:34)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:22)
Message:

cpp: added queue

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/cpp/include/impl/queue.hpp

    r3f7031a r23dcc14  
    3030#define LIBCPP_QUEUE
    3131
     32#include <deque>
     33#include <memory>
     34#include <type_traits>
     35#include <utility>
     36#include <vector>
     37
    3238namespace std
    3339{
     40    /**
     41     * 23.6.3, class template queue:
     42     */
     43
    3444    template<class T, class Container = deque<T>>
    35     class queue;
     45    class queue
     46    {
     47        public:
     48            using value_type      = typename Container::value_type;
     49            using reference       = typename Container::reference;
     50            using const_reference = typename Container::const_reference;
     51            using size_type       = typename Container::size_type;
     52            using container_type  = Container;
     53
     54            explicit queue(const container_type& cc)
     55                : c{cc}
     56            { /* DUMMY BODY */ }
     57
     58            explicit queue(container_type&& cc = container_type{})
     59                : c{move(cc)}
     60            { /* DUMMY BODY */ }
     61
     62            template<
     63                class Alloc,
     64                class = enable_if_t<uses_allocator<container_type, Alloc>::value, void>
     65            >
     66            explicit queue(const Alloc& alloc)
     67                : c{alloc}
     68            { /* DUMMY BODY */}
     69
     70            template<
     71                class Alloc,
     72                class = enable_if_t<uses_allocator<container_type, Alloc>::value, void>
     73            >
     74            queue(const container_type& cc, const Alloc& alloc)
     75                : c{cc, alloc}
     76            { /* DUMMY BODY */}
     77
     78            template<
     79                class Alloc,
     80                class = enable_if_t<uses_allocator<container_type, Alloc>::value, void>
     81            >
     82            queue(container_type&& cc, const Alloc& alloc)
     83                : c{move(cc), alloc}
     84            { /* DUMMY BODY */}
     85
     86            template<
     87                class Alloc,
     88                class = enable_if_t<uses_allocator<container_type, Alloc>::value, void>
     89            >
     90            queue(const queue& other, const Alloc& alloc)
     91                : c{other.c, alloc}
     92            { /* DUMMY BODY */}
     93
     94            template<
     95                class Alloc,
     96                class = enable_if_t<uses_allocator<container_type, Alloc>::value, void>
     97            >
     98            queue(queue&& other, const Alloc& alloc)
     99                : c{move(other.c), alloc}
     100            { /* DUMMY BODY */}
     101
     102            bool empty() const
     103            {
     104                return c.empty();
     105            }
     106
     107            size_type size() const
     108            {
     109                return c.size();
     110            }
     111
     112            reference front()
     113            {
     114                return c.front();
     115            }
     116
     117            const_reference front() const
     118            {
     119                return c.front();
     120            }
     121
     122            reference back()
     123            {
     124                return c.back();
     125            }
     126
     127            const_reference back() const
     128            {
     129                return c.back();
     130            }
     131
     132            void push(const value_type& val)
     133            {
     134                c.push_back(val);
     135            }
     136
     137            void push(value_type&& val)
     138            {
     139                c.push_back(forward<value_type>(val));
     140            }
     141
     142            template<class... Args>
     143            void emplace(Args&&... args)
     144            {
     145                c.emplace_back(forward<Args>(args)...);
     146            }
     147
     148            void pop()
     149            {
     150                c.pop_front();
     151            }
     152
     153        protected:
     154            container_type c;
     155
     156        public: // The noexcept part of swap's declaration needs c to be declared.
     157            void swap(queue& other)
     158                noexcept(noexcept(swap(c, other.c)))
     159            {
     160                std::swap(c, other.c);
     161            }
     162
     163        private:
     164            template<class U, class C>
     165            friend bool operator==(const queue<U, C>&, const queue<U, C>&);
     166
     167            template<class U, class C>
     168            friend bool operator<(const queue<U, C>&, const queue<U, C>&);
     169
     170            template<class U, class C>
     171            friend bool operator!=(const queue<U, C>&, const queue<U, C>&);
     172
     173            template<class U, class C>
     174            friend bool operator>(const queue<U, C>&, const queue<U, C>&);
     175
     176            template<class U, class C>
     177            friend bool operator>=(const queue<U, C>&, const queue<U, C>&);
     178
     179            template<class U, class C>
     180            friend bool operator<=(const queue<U, C>&, const queue<U, C>&);
     181    };
     182
     183    template<class T, class Container, class Alloc>
     184    struct uses_allocator<queue<T, Container>, Alloc>
     185        : uses_allocator<Container, Alloc>
     186    { /* DUMMY BODY */ };
    36187
    37188    template<
Note: See TracChangeset for help on using the changeset viewer.