| 1 | // Copyright (C) 2021 T. Zachary Laine |
| 2 | // |
| 3 | // Distributed under the Boost Software License, Version 1.0. (See |
| 4 | // accompanying file LICENSE_1_0.txt or copy at |
| 5 | // http://www.boost.org/LICENSE_1_0.txt) |
| 6 | #ifndef BOOST_STL_INTERFACES_USE_CONCEPTS |
| 7 | |
| 8 | void compile_seq_cont_constrained_pop_back() {} |
| 9 | |
| 10 | #else |
| 11 | |
| 12 | #include <initializer_list> |
| 13 | #include <memory> |
| 14 | #include <type_traits> |
| 15 | #include <utility> |
| 16 | #include <vector> |
| 17 | |
| 18 | #include <boost/stl_interfaces/sequence_container_interface.hpp> |
| 19 | |
| 20 | template<class T> |
| 21 | struct container : boost::stl_interfaces::sequence_container_interface< |
| 22 | container<T>, |
| 23 | boost::stl_interfaces::element_layout::contiguous> |
| 24 | { |
| 25 | public: |
| 26 | using super = boost::stl_interfaces::sequence_container_interface< |
| 27 | container<T>, |
| 28 | boost::stl_interfaces::element_layout::contiguous>; |
| 29 | using container_type = std::vector<T>; |
| 30 | |
| 31 | using value_type = typename container_type::value_type; |
| 32 | using reference = typename container_type::reference; |
| 33 | using const_reference = typename container_type::const_reference; |
| 34 | using iterator = typename container_type::iterator; |
| 35 | using const_iterator = typename container_type::const_iterator; |
| 36 | using difference_type = typename container_type::difference_type; |
| 37 | using size_type = typename container_type::size_type; |
| 38 | |
| 39 | container() = default; |
| 40 | container(const container &) = default; |
| 41 | container(container &&) = default; |
| 42 | ~container() = default; |
| 43 | container & operator=(const container &) = default; |
| 44 | container & operator=(container &&) = default; |
| 45 | |
| 46 | container(size_type count, const_reference value) : c(count, value) {} |
| 47 | container(std::initializer_list<value_type> init) : c(init) {} |
| 48 | |
| 49 | template<class InputIt> |
| 50 | container(InputIt first, InputIt last) : c(first, last) |
| 51 | {} |
| 52 | |
| 53 | iterator begin() noexcept { return c.begin(); } |
| 54 | iterator end() noexcept { return c.end(); } |
| 55 | |
| 56 | size_type max_size() const noexcept { return c.max_size(); } |
| 57 | |
| 58 | template<class InputIt> |
| 59 | iterator insert(const_iterator pos, InputIt first, InputIt last) |
| 60 | { |
| 61 | return c.insert(pos, first, last); |
| 62 | } |
| 63 | |
| 64 | template<class... Args> |
| 65 | iterator emplace(const_iterator pos, Args &&... args) |
| 66 | { |
| 67 | return c.emplace(pos, std::forward<Args>(args)...); |
| 68 | } |
| 69 | |
| 70 | iterator erase(const_iterator first, const_iterator last) |
| 71 | { |
| 72 | return c.erase(first, last); |
| 73 | } |
| 74 | |
| 75 | template<class... Args> |
| 76 | requires(std::constructible_from<value_type, Args &&...>) reference |
| 77 | emplace_back(Args &&... args) |
| 78 | { |
| 79 | return c.emplace_back(std::forward<Args>(args)...); |
| 80 | } |
| 81 | |
| 82 | void swap(container & other) { c.swap(other.c); } |
| 83 | |
| 84 | using super::begin; |
| 85 | using super::end; |
| 86 | using super::insert; |
| 87 | using super::erase; |
| 88 | |
| 89 | private: |
| 90 | container_type c; |
| 91 | }; |
| 92 | |
| 93 | void compile_seq_cont_constrained_pop_back() |
| 94 | { |
| 95 | { |
| 96 | std::vector<int> v; |
| 97 | v.emplace_back(0); |
| 98 | v.pop_back(); |
| 99 | |
| 100 | container<int> c; |
| 101 | c.emplace_back(0); |
| 102 | c.pop_back(); |
| 103 | } |
| 104 | |
| 105 | { |
| 106 | std::vector<std::unique_ptr<int>> v; |
| 107 | v.emplace_back(new int); |
| 108 | v.pop_back(); |
| 109 | |
| 110 | container<std::unique_ptr<int>> c; |
| 111 | c.emplace_back(new int); |
| 112 | c.pop_back(); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | #endif |
| 117 | |