### Friendship example: list.cpp Source: https://joholl.github.io/pitchfork-website An empty source file that includes the header to ensure it compiles in isolation. This verifies that the header has all necessary includes and forward declarations. ```cpp // list.cpp #include "list.hpp" ``` -------------------------------- ### PIMPL example: connection.cpp Source: https://joholl.github.io/pitchfork-website Implementation file for the connection class. It defines the implementation class and a helper function to initialize the private data, then implements the constructor and destructor. ```cpp #include "connection.hpp" namespace acme::detail { class connection_impl { // Whatever we need for the connection... }; } namespace { std::unique_ptr init_private_data(const std::string& address) { // Initialize and return the connection data... } } acme::connection::~connection() = default; acme::connection::connection(const std::string& address) : _impl{ init_private_data(address) } {} ``` -------------------------------- ### PIMPL example: connection.hpp Source: https://joholl.github.io/pitchfork-website Header for a connection class using the PIMPL idiom. It forward-declares the implementation class and holds a unique_ptr to it, hiding the implementation details. ```cpp // connection.hpp #include namespace acme { // Forward-declare the private member data type namespace detail { class connection_ipml; } // The wrapper class class connection { private: // The actual PIMPL std::unique_ptr _impl; public: connection(const std::string& address); ~connection(); }; } ``` -------------------------------- ### Friendship example: list.hpp Source: https://joholl.github.io/pitchfork-website Shows a list class template and its iterator as a single logical component using friendship. The iterator has a private constructor that only the list class can call, and the list class declares the iterator as a friend. ```cpp // list.hpp namespace acme { template class list; namespace detail { // Class implementing a "list iterator" template class list_iterator { public: // Public default constructor list_iterator() = default; private: // A private constructor used to initialize the iterator to the proper state explicit list_iterator(list&); // Permit our list class to construct us with the private constructor friend class list; }; } template class list { public: using iterator = detail::list_iterator; // The iterator class is a friend, giving it access to our internals friend class detail::list_iterator; }; } ``` -------------------------------- ### Separate header placement directory layout Source: https://joholl.github.io/pitchfork-website Shows the resulting directory structure when using separate header placement, with public headers in include/ and compilable sources in src/. The relative path from the source directory to the parent directory of the source file must match that of the header. ```text / include/ cat/ sounds/ meow.hpp src/ cat/ sounds/ meow.cpp ``` -------------------------------- ### Merged header placement directory layout Source: https://joholl.github.io/pitchfork-website Shows the resulting directory structure when using merged header placement, with both header and source files in the same src/ directory. The files of a physical component are siblings in the same directory. ```text / src/ cat/ sounds/ hiss.hpp hiss.cpp ``` -------------------------------- ### Source tree layout for subdivided circle component Source: https://joholl.github.io/pitchfork-website Shows the directory and file layout for the logical component `geo::shapes::circle` when splitting complex member functions `circumference()` and `area()` into separate translation units. The header `circle.hpp` appears in `src/geo/shapes/`, alongside the main implementation and per-function implementations, plus the unit test `circle.test.cpp`. ```plaintext src/geo/shapes/ circle.hpp circle.cpp circle.circumference.cpp circle.area.cpp circle.test.cpp ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.