> For the complete documentation index, see [llms.txt](https://docs.werwolv.net/pattern-language/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.werwolv.net/pattern-language/core-language/namespaces.md).

# Namespaces

Namespaces provide a way to encapsulate and group multiple similar types together. They also allow for multiple types in different namespaces to be named the same without interfering with each other.

```cpp
namespace abc {

    struct Type {
        u32 x;
    };

}

abc::Type type1 @ 0x100;

using Type = abc::Type;
Type type2 @ 0x200;
```

To access a type within a namespace, the scope resolution operator `::` is used. In the example above, to access the type `Type` inside the namespace `abc`, `abc::Type` is used.

## Nested and Reopened Namespaces

You can also define **nested namespaces** and reopen them later. This is especially useful for organizing internal constants and helper logic related to the main types, while keeping them encapsulated.

```cpp
namespace game {

    struct User {
        u32 id;
        u32 age;
    } [[format("game::impl::format_user")]];

    namespace impl {
        fn format_user(User user) {
            return std::format("User({}, {})", user.id, user.age);
        };
    }

    struct Score {
        u32 points;
        u32 level;
    } [[format("game::impl::format_score")]];

    namespace impl {
        fn format_score(Score score) {
            return std::format("Score({}, {})", score.points, score.level);
        };
    }

}
```

These separate blocks both add to the same `game::impl` namespace. This provides a clean separation between public type definitions and internal helper logic and improves readablity.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.werwolv.net/pattern-language/core-language/namespaces.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
