72 std::swap(
ptr, f.ptr);
86 else if (
ptr ==
nullptr)
119 throw std::logic_error(
"attempt to access value of moved-from Foo");
130 for (
size_t i = 0; i < q.
size(); ++i)
131 cout << (
T) q.
front(i) <<
" ";
134 for (
size_t i = 0; i < q.
size(); ++i)
135 cout << (
T) q.
rear(i) <<
" ";
143 cout <<
"Creating rval queue ";
145 for (
int i = 0; i < n; ++i)
146 cout << q.
put(
T(i)) <<
" ";
156 cout <<
"testQueue -- exercises ArrayQueue with insert, consult, and delete operations\n"
158 <<
"Creates an ArrayQueue<int> of the given size, fills it, reads back\n"
159 <<
"elements, drains in steps of 3 until underflow, refills, then deletes\n"
160 <<
"a specified number of items. Finally tests copy and move constructors\n"
161 <<
"with both int and a heap-allocating Foo type.\n"
164 <<
" " <<
argv[0] <<
" <queue-size> <items-to-delete>\n"
167 <<
" queue-size Capacity of the queue and number of items to insert\n"
168 <<
" items-to-delete Number of items to remove in the second phase\n"
171 <<
" " <<
argv[0] <<
" 20 7\n"
172 <<
" Creates a queue of capacity 20, inserts 20 items, then deletes 7.\n";
178 cerr <<
"Usage: " <<
argv[0] <<
" <queue-size> <items-to-delete>" <<
endl;
179 cerr <<
"Both arguments must be non-negative integers." <<
endl;
191 cerr <<
"Error: Invalid queue size argument. Must be a non-negative integer fitting in int." <<
endl;
195 int n =
static_cast<int>(
n_long);
200 cout <<
"Inserting " << n <<
" values ";
201 for (
size_t i = 0; i < n; ++i)
202 cout << q.
put(i) <<
" ";
207 cout <<
"Consulting all values until underflow ";
208 for (
int i = 0; 1; i++)
215 catch (std::range_error &
exc)
223 cout <<
"Deleting all values in steps of 3 until underflow ";
230 catch (std::underflow_error &
exc)
240 cout <<
"Inserting " << n <<
" values " <<
endl;
241 for (
size_t i = 0; i < n; ++i)
242 cout << q.
put(i) <<
" ";
255 cerr <<
"Error: Invalid items-to-delete argument. Must be a non-negative integer fitting in int." <<
endl;
259 int m =
static_cast<int>(
m_long);
261 cout <<
"Deleting " <<
m <<
" items" <<
endl;
262 for (
int i = 0; i <
m; i++)
266 cout << q.
get() <<
" ";
268 catch (std::underflow_error &
exc)
277 cout <<
"q = " <<
endl;
280 cout <<
"Testing constructors ... " <<
endl;
Queue implemented with a single dynamic array.
T & front(const size_t i=0) const
Return the i-th oldest item of the queue.
T & getn(const size_t i)
Remove the i oldest items of the queue.
T & put(const T &item)
Copy and put an item in the queue.
T & rear(const size_t i=0) const
Return the i-th youngest item of the queue.
T get()
Remove the oldest item of the queue and return a copy.
size_t size() const noexcept
Return the number of elements.
constexpr size_t capacity() const noexcept
The type of element of array.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
std::decay_t< typename HeadC::Item_Type > T
std::unique_ptr< int > ptr
Foo & operator=(const Foo &f)
FooMap m(5, fst_unit_pair_hash, snd_unit_pair_hash)
ArrayQueue< T > create_queue(int n)
void print(const ArrayQueue< T > &q)
Circular queue implementations backed by arrays.