Initial commit
This commit is contained in:
commit
4f4397b3e1
48 changed files with 2002 additions and 0 deletions
|
|
@ -0,0 +1,34 @@
|
|||
#pragma once
|
||||
|
||||
#include "../../generator/generator.h"
|
||||
#include "AbstractVectorFactory.h"
|
||||
#include <algorithm>
|
||||
#include <execution>
|
||||
|
||||
namespace atlas::collection {
|
||||
template <typename T>
|
||||
class AutoThreadedVectorFactory : public AbstractVectorFactory<T> {
|
||||
|
||||
public:
|
||||
AutoThreadedVectorFactory(std::function<std::unique_ptr<generator::Generator<T>>()> generator_factory)
|
||||
: m_gen { std::move(generator_factory) }
|
||||
{
|
||||
}
|
||||
|
||||
AutoThreadedVectorFactory(AutoThreadedVectorFactory const&) = delete;
|
||||
AutoThreadedVectorFactory(AutoThreadedVectorFactory&&) = delete;
|
||||
AutoThreadedVectorFactory& operator=(AutoThreadedVectorFactory const&) = delete;
|
||||
AutoThreadedVectorFactory& operator=(AutoThreadedVectorFactory&&) = delete;
|
||||
|
||||
auto fill(std::vector<T>& v) -> void override final
|
||||
{
|
||||
std::for_each(std::execution::par_unseq, v.begin(), v.end(), [this](auto& v) {
|
||||
static thread_local auto gen { m_gen() };
|
||||
v = gen->next();
|
||||
});
|
||||
}
|
||||
|
||||
private:
|
||||
std::function<std::unique_ptr<generator::Generator<T>>()> m_gen;
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue