<commit_before>#include <iostream>

template <typename Value_t, typename Initialized_t>
class LazyInitialized
{
	public:
		LazyInitialized(Initialized_t i) : m_i(i), m_v(), m_needInit(true) {}
		operator Value_t() 
		{ 
			if ( m_needInit ) m_v = m_i();
			m_needInit = false;
			return m_v;
		}

	private:
		Initialized_t m_i;
		Value_t m_v;
		bool m_needInit;
};

template<typename Value_t, typename Initialized_t>
LazyInitialized<Value_t,Initialized_t> 
make_lazy_initialized(Initialized_t i) 
{
	return LazyInitialized<Value_t,Initialized_t>(i);
}

int main(int argc, char* argv[])
{
	auto x = make_lazy_initialized<double>([]()->double{std::cout << "Built" << std::endl; return 2.0;});
	std::cout << x << std::endl;
	std::cout << x << std::endl;
}
<commit_msg>Lazy initialized member variable<commit_after>#include <iostream>

template <typename Value_t, typename Initializer_t>
class LazyInitialized
{
	public:
		LazyInitialized(Initializer_t i) : m_i(i), m_v(), m_needInit(true) {}
		operator Value_t() 
		{ 
			if ( m_needInit ) m_v = m_i();
			m_needInit = false;
			return m_v;
		}

	private:
		Initializer_t m_i;
		Value_t m_v;
		bool m_needInit;
};

template<typename Value_t, typename Initializer_t>
LazyInitialized<Value_t,Initializer_t> 
make_lazy_initialized(Initializer_t i) 
{
	return LazyInitialized<Value_t,Initializer_t>(i);
}

struct ClassWithLazyMembers
{
	LazyInitialized<double, std::function<double (void)> > m_baseLazyValue;
	LazyInitialized<double, std::function<double (void)> > m_lazyValue;
  
	ClassWithLazyMembers() : 
		m_baseLazyValue{[]()->double{return 2.0;}},
		m_lazyValue{[this]()->double{std::cout << "Built member variable" << std::endl; return 2.0 * this->m_baseLazyValue;}} {}
	
};

int main(int argc, char* argv[])
{
	auto x = make_lazy_initialized<double>([]()->double{std::cout << "Built" << std::endl; return 2.0;});
	std::cout << x << std::endl;
	std::cout << x << std::endl;

	ClassWithLazyMembers c;
	std::cout << c.m_lazyValue << std::endl;
	std::cout << c.m_lazyValue << std::endl;
}

{'fraction_non_alphanumeric': 0.15324165029469547, 'fraction_numerical': 0.003929273084479371, 'mean_word_length': 5.592233009708738, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 24, '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': '1346988', 'n_tokens_mistral': 810, 'n_tokens_neox': 788, 'n_words': 150}