29 #ifndef _util_container_thread_wrap_h
30 #define _util_container_thread_wrap_h
38 template <
typename STLContainer>
39 STLContainer merge(
const std::vector<STLContainer>& containers) {
41 for(
auto&& c : containers) {
42 std::copy(c.begin(), c.end(), std::back_inserter(rv));
47 template <
typename STLContainer>
48 STLContainer sum_merge(
const std::vector<STLContainer>& containers) {
49 STLContainer rv = containers[0];
51 for(
auto&& c : containers) {
57 for(
auto&& item : c) {
58 MPQC_ASSERT(offset <= c.size());
69 template <
typename Container>
71 Container operator()(
const std::vector<Container>& containers)
const {
72 return merge(containers);
76 template <
typename Container>
78 Container operator()(
const std::vector<Container>& containers)
const {
79 return sum_merge(containers);
86 template <
typename Container,
typename Merger=detail::_Merger<Container>>
91 std::vector<Container> thread_containers_;
103 thread_containers_(nthread)
106 void set_nthread(
int nthr) {
108 thread_containers_.resize(nthr);
111 Container& mine(
int ithr) {
112 return thread_containers_[ithr];
115 operator Container()
const {
116 return merger_(thread_containers_);
119 Container merged()
const {
120 return merger_(thread_containers_);