<commit_before>// The PIMPL idiom

// foo.h - header file

#include <memory>

class foo
{
	public:
		foo();

	private:
		class impl;
		std::unique_ptr<impl> pimpl;
};


// foo.cpp - implementation file

class foo::impl
{
	public:
		void do_internal_work()
		{
			internal_data = 5;
		}

	private:
		int internal_data = 0;
};

foo::foo()
	: pimpl{std::make_unique<impl>()}
{
	pimpl->do_internal_work();
}

// Remove compilation dependencies on internal class implementations
// and improve compile times.
// 
// When a header file changes, any files that `#include` that file
// will need to be recompiled. In the case of a class header, this
// is true even if those changes only apply to private members of the
// class. The PIMPL idiom hides private members from any users of
// the header file, allowing these internal details to change without
// requiring recompilation of the client code.
// 
// [!7-15] define a class, `foo`, to which we have applied the PIMPL
// idiom. This class definition includes only the public interface
// of the class and a pointer to the internal implementation. We use
// a [`std::unique_ptr`](cpp/memory/unique_ptr) ([14]) to ensure
// the lifetime of the implementation is managed correctly, which we
// initialise in `foo`s constructor ([33]).
// 
// While the internal implementation class, `impl`, is declared in
// the header file on [13], its definition appears in the
// implementation file on [20-30]. This allows the class definition
// to change without requiring users of `foo` to recompile.

int main()
{
	foo f;
}<commit_msg>Fix PImpl: destructor needs to be out-of-line.<commit_after>// The PIMPL idiom

// foo.h - header file

#include <memory>

class foo
{
	public:
		// Constructor and destructor need to be out-of-line because of std::unique_ptr
		foo();
		~foo();

		// Copy are implicitly disabled, you need to declare them yourself.
		// foo(const foo &);
		// foo &operator=(const foo &);

		// Move is implicitely disabled, you need to re-enable them explicitly.
		foo(foo &&);
		foo &operator=(foo &&);

	private:
		class impl;
		std::unique_ptr<impl> pimpl;
};


// foo.cpp - implementation file

class foo::impl
{
	public:
		void do_internal_work()
		{
			internal_data = 5;
		}

	private:
		int internal_data = 0;
};

foo::foo()
	: pimpl{std::make_unique<impl>()}
{
	pimpl->do_internal_work();
}

foo::~foo() = default;
foo::foo(foo &&) = default;
foo &foo::operator=(foo &&) = default;


// Remove compilation dependencies on internal class implementations
// and improve compile times.
// 
// When a header file changes, any files that `#include` that file
// will need to be recompiled. In the case of a class header, this
// is true even if those changes only apply to private members of the
// class. The PIMPL idiom hides private members from any users of
// the header file, allowing these internal details to change without
// requiring recompilation of the client code.
// 
// [!7-15] define a class, `foo`, to which we have applied the PIMPL
// idiom. This class definition includes only the public interface
// of the class and a pointer to the internal implementation. We use
// a [`std::unique_ptr`](cpp/memory/unique_ptr) ([14]) to ensure
// the lifetime of the implementation is managed correctly, which we
// initialise in `foo`s constructor ([33]).
// 
// While the internal implementation class, `impl`, is declared in
// the header file on [13], its definition appears in the
// implementation file on [20-30]. This allows the class definition
// to change without requiring users of `foo` to recompile.

int main()
{
	foo f;
	foo h = std::move(f); // call move constructor to build h
}
{'fraction_non_alphanumeric': 0.11395856052344602, 'fraction_numerical': 0.008178844056706653, 'mean_word_length': 3.535228677379481, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '3375045', 'n_tokens_mistral': 1134, 'n_tokens_neox': 1071, 'n_words': 469}