Vince's CSV Parser
Loading...
Searching...
No Matches
row_deque.hpp
Go to the documentation of this file.
1
5#pragma once
6
7#include "common.hpp"
8
9#include <vector>
10
11#if CSV_ENABLE_THREADS
12#include "thread_safe_deque.hpp"
13#else
15#endif
16
17#include <cstddef>
18#include <type_traits>
19#include <utility>
20
21#ifdef CSV_HAS_CXX20
22#include <concepts>
23#endif
24
25namespace csv {
26 namespace internals {
27#if !CSV_ENABLE_THREADS
28 template<typename T>
29 using ThreadSafeDeque = SingleThreadDeque<T>;
30#endif
31
32#ifdef CSV_HAS_CXX20
33 // This concept is intentionally limited to parser queue semantics.
34 // Diagnostics such as ThreadSafeDeque::inspect() stay out of the
35 // contract so single-threaded and threaded queues can use different
36 // storage without inventing a generic inspection-view abstraction.
37 template<typename Q, typename T>
38 concept RowDequeLike = requires(Q q, const Q cq, T item, size_t n, std::vector<T> batch) {
39 { Q(100) };
40 { q.push_back(std::move(item)) } -> std::same_as<void>;
41 { q.append_rows(std::move(batch)) } -> std::same_as<void>;
42 { q.pop_front() } -> std::same_as<T>;
43 { q.drain_front(batch, n) } -> std::same_as<size_t>;
44 { cq.empty() } -> std::same_as<bool>;
45 { cq.is_waitable() } -> std::same_as<bool>;
46 { q.wait() } -> std::same_as<void>;
47 { q.notify_all() } -> std::same_as<void>;
48 { q.kill_all() } -> std::same_as<void>;
49 { cq.size() } -> std::same_as<size_t>;
50 };
51
52#if CSV_ENABLE_THREADS
53 static_assert(RowDequeLike<ThreadSafeDeque<int>, int>, "ThreadSafeDeque must satisfy RowDequeLike contract");
54#else
55 static_assert(RowDequeLike<SingleThreadDeque<int>, int>, "SingleThreadDeque must satisfy RowDequeLike contract");
56 static_assert(RowDequeLike<ThreadSafeDeque<int>, int>, "Selected ThreadSafeDeque alias must satisfy RowDequeLike contract");
57#endif
58#endif
59 }
60}
A standalone header file containing shared code.
The all encompassing namespace.
Single-threaded row deque implementation.
Thread-safe deque for producer-consumer patterns.