#ifndef ALSK_ALSK_CONTEXT_CONTEXT_H #define ALSK_ALSK_CONTEXT_CONTEXT_H #include #include #include #include #include "../skeleton/link/args/placeholders.h" namespace alsk { template class Context { public: using Id = std::size_t; using Args = std::tuple; using Seed = decltype(+RNG::default_seed); private: Id _idCount; std::vector _rng; std::vector _args; public: Seed seed; public: constexpr Context(): _idCount{0}, seed{RNG::default_seed} {} void setup(Id idCount = 30) { if(idCount <= _idCount) return; Id baseId = _idCount; _idCount = idCount; RNG seeder{seed}; _rng.reserve(idCount); for(Id id = baseId; id < idCount; ++id) _rng.emplace_back(seeder()); _args.reserve(idCount); for(Id id = baseId; id < idCount; ++id) _args.emplace_back(id, std::ref(_rng[id])); } void reset() { RNG seeder{seed}; _rng.clear(); for(Id id = 0; id < _idCount; ++id) _rng.emplace_back(seeder()); _args.clear(); for(Id id = 0; id < _idCount; ++id) _args.emplace_back(id, std::ref(_rng[id])); } constexpr Id maxId() const noexcept { return _idCount; } Args& args(Id const& id) { return _args[id]; } ~Context() noexcept {} }; using DefaultContext = Context; namespace arg { /** * CtxId * to get own's context identifier */ using CtxId = C<0>; /** * RNG * for random number generator */ using RNG = C<1>; } } #endif