<commit_before>#pragma once

#include "../container.hpp"
#include "invoke.hpp"
#include "single.hpp"
#include "injected.hpp"

#include <type_traits>

namespace kgr {

template<typename... Args>
struct Dependency {};

template<typename CRTP, typename Type>
struct GenericService {
	friend struct Container;
	using Self = CRTP;
	
	GenericService() = default;
	
	GenericService(GenericService&& other) {
		if (other._initialized) {
			emplace(std::move(other.getInstance()));
		}
	}
	
	GenericService& operator=(GenericService&& other) {
		if (other._initialized) {
			emplace(std::move(other.getInstance()));
		}
		return *this;
	}
	
	GenericService(const GenericService& other) {
		if (other._initialized) {
			emplace(other.getInstance());
		}
	}
	
	GenericService& operator=(const GenericService& other) {
		if (other._initialized) {
			emplace(other.getInstance());
		}
		return *this;
	}
	
	template<typename... Args>
	GenericService(in_place_t, Args&&... args) {
		emplace(std::forward<Args>(args)...);
	}
	
	~GenericService() {
		if (_initialized) {
			getInstance().~Type();
		}
	}
	
protected:
	template<typename F, typename... T>
	void autocall(Inject<T>... others) {
		CRTP::call(getInstance(), F::value, std::forward<Inject<T>>(others).forward()...);
	}
	
	template<typename F, template<typename> class Map>
	void autocall(Inject<ContainerService> cs) {
		autocall<Map, F>(detail::tuple_seq<detail::function_arguments_t<typename F::value_type>>{}, std::move(cs));
	}
	
	Type& getInstance() {
		return *reinterpret_cast<Type*>(&_instance);
	}
	
	const Type& getInstance() const {
		return *reinterpret_cast<const Type*>(&_instance);
	}
	
private:
	template<typename... Args>
	void emplace(Args&&... args) {
		if (_initialized) {
			getInstance().~Type();
		}
		
		_initialized = true;
		new (&_instance) Type(std::forward<Args>(args)...);
	}
	
	template<template<typename> class Map, typename F, int... S>
	void autocall(detail::seq<S...>, Inject<ContainerService> cs) {
		cs.forward().invoke<Map>([this](detail::function_argument_t<S, typename F::value_type>... args){
			CRTP::call(getInstance(), F::value, std::forward<detail::function_argument_t<S, typename F::value_type>>(args)...);
		});
	}
	
	bool _initialized = false;
	typename std::aligned_storage<sizeof(Type), alignof(Type)>::type _instance;
};

} // namespace kgr
<commit_msg>no need to check data. The data is always good.<commit_after>#pragma once

#include "../container.hpp"
#include "invoke.hpp"
#include "single.hpp"
#include "injected.hpp"

#include <type_traits>

namespace kgr {

template<typename... Args>
struct Dependency {};

template<typename CRTP, typename Type>
struct GenericService {
	friend struct Container;
	using Self = CRTP;
	
	GenericService() = default;
	
	GenericService(GenericService&& other) {
		emplace(std::move(other.getInstance()));
	}
	
	GenericService& operator=(GenericService&& other) {
		emplace(std::move(other.getInstance()));
		return *this;
	}
	
	GenericService(const GenericService& other) {
		emplace(other.getInstance());
	}
	
	GenericService& operator=(const GenericService& other) {
		emplace(other.getInstance());
		return *this;
	}
	
	template<typename... Args>
	GenericService(in_place_t, Args&&... args) {
		emplace(std::forward<Args>(args)...);
	}
	
	~GenericService() {
		getInstance().~Type();
	}
	
protected:
	template<typename F, typename... T>
	void autocall(Inject<T>... others) {
		CRTP::call(getInstance(), F::value, std::forward<Inject<T>>(others).forward()...);
	}
	
	template<typename F, template<typename> class Map>
	void autocall(Inject<ContainerService> cs) {
		autocall<Map, F>(detail::tuple_seq<detail::function_arguments_t<typename F::value_type>>{}, std::move(cs));
	}
	
	Type& getInstance() {
		return *reinterpret_cast<Type*>(&_instance);
	}
	
	const Type& getInstance() const {
		return *reinterpret_cast<const Type*>(&_instance);
	}
	
private:
	template<typename... Args>
	void emplace(Args&&... args) {
		new (&_instance) Type(std::forward<Args>(args)...);
	}
	
	template<template<typename> class Map, typename F, int... S>
	void autocall(detail::seq<S...>, Inject<ContainerService> cs) {
		cs.forward().invoke<Map>([this](detail::function_argument_t<S, typename F::value_type>... args){
			CRTP::call(getInstance(), F::value, std::forward<detail::function_argument_t<S, typename F::value_type>>(args)...);
		});
	}
	
	typename std::aligned_storage<sizeof(Type), alignof(Type)>::type _instance;
};

} // namespace kgr

{'fraction_non_alphanumeric': 0.17483769867920304, 'fraction_numerical': 0.0, 'mean_word_length': 5.128943758573389, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4132419', 'n_tokens_mistral': 1570, 'n_tokens_neox': 1456, 'n_words': 285}