Skip to content

[C++] Constrain TElement to trivially copyable types (C# where TElement : struct) #132

Backlog

Description

@konard

Location: cpp/Platform.Memory/FileArrayMemory.h:14

Current code:

template <typename TElement> class FileArrayMemory<TElement> final : public IArrayMemory<TElement>
    //where TElement : struct

Problem:
The C# constraint where TElement : struct was left as a comment during translation, so the C++ templates accept any TElement. FileArrayMemory, DirectMemoryAsArrayMemoryAdapter and ArrayMemory copy elements as raw bytes, which is only valid for trivially copyable types.

Suggestion:
Express the constraint in C++ (C++20 requires std::is_trivially_copyable_v<TElement> or a static_assert) for FileArrayMemory and DirectMemoryAsArrayMemoryAdapter (C# has the same constraint on both), and add a compile-time test.


Converted from a comment as part of #15.

Activity

  1. added
    enhancement
    on Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions