File: compile_seq_cont_rvalue_constrained_pop_back.cpp

package info (click to toggle)
boost1.90 1.90.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 593,156 kB
  • sloc: cpp: 4,190,642; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,776; makefile: 1,161; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (116 lines) | stat: -rw-r--r-- 3,226 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright (C) 2021 T. Zachary Laine
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_STL_INTERFACES_USE_CONCEPTS

void compile_seq_cont_constrained_pop_back() {}

#else

#include <initializer_list>
#include <memory>
#include <type_traits>
#include <utility>
#include <vector>

#include <boost/stl_interfaces/sequence_container_interface.hpp>

template<class T>
struct container : boost::stl_interfaces::sequence_container_interface<
                       container<T>,
                       boost::stl_interfaces::element_layout::contiguous>
{
public:
    using super = boost::stl_interfaces::sequence_container_interface<
        container<T>,
        boost::stl_interfaces::element_layout::contiguous>;
    using container_type = std::vector<T>;

    using value_type = typename container_type::value_type;
    using reference = typename container_type::reference;
    using const_reference = typename container_type::const_reference;
    using iterator = typename container_type::iterator;
    using const_iterator = typename container_type::const_iterator;
    using difference_type = typename container_type::difference_type;
    using size_type = typename container_type::size_type;

    container() = default;
    container(const container &) = default;
    container(container &&) = default;
    ~container() = default;
    container & operator=(const container &) = default;
    container & operator=(container &&) = default;

    container(size_type count, const_reference value) : c(count, value) {}
    container(std::initializer_list<value_type> init) : c(init) {}

    template<class InputIt>
    container(InputIt first, InputIt last) : c(first, last)
    {}

    iterator begin() noexcept { return c.begin(); }
    iterator end() noexcept { return c.end(); }

    size_type max_size() const noexcept { return c.max_size(); }

    template<class InputIt>
    iterator insert(const_iterator pos, InputIt first, InputIt last)
    {
        return c.insert(pos, first, last);
    }

    template<class... Args>
    iterator emplace(const_iterator pos, Args &&... args)
    {
        return c.emplace(pos, std::forward<Args>(args)...);
    }

    iterator erase(const_iterator first, const_iterator last)
    {
        return c.erase(first, last);
    }

    template<class... Args>
    requires(std::constructible_from<value_type, Args &&...>) reference
        emplace_back(Args &&... args)
    {
        return c.emplace_back(std::forward<Args>(args)...);
    }

    void swap(container & other) { c.swap(other.c); }

    using super::begin;
    using super::end;
    using super::insert;
    using super::erase;

private:
    container_type c;
};

void compile_seq_cont_constrained_pop_back()
{
    {
        std::vector<int> v;
        v.emplace_back(0);
        v.pop_back();

        container<int> c;
        c.emplace_back(0);
        c.pop_back();
    }

    {
        std::vector<std::unique_ptr<int>> v;
        v.emplace_back(new int);
        v.pop_back();

        container<std::unique_ptr<int>> c;
        c.emplace_back(new int);
        c.pop_back();
    }
}

#endif