Skip to content

add std::array constructor overloads and tests - #57

Draft
0xull wants to merge 1 commit into
rustfoundation:mainfrom
0xull:array-overloads
Draft

0xull wants to merge 1 commit into
rustfoundation:mainfrom
0xull:array-overloads

Conversation

@0xull

@0xull 0xull commented Oct 16, 2026

Copy link
Copy Markdown

this commit covers std::array overloads, starting with the constructors. next to_array and get will be my focus for the next commits.

std::array constructors are aggregate initialization with 0 to N initializers, in addition with its copy and move constructors. its overloads doesn't clash like other data structures, like say forward_list for count/value cases.

c++ has two zero-argument forms (a; and a{};), but only one of them can be a rust overload, so i used value-initialization.

for the other overloaded methods on std::array which only differ by const or &/&&, i’m plan to use get and to_array as the examples for that rule.

ai use: i used claude (web) to get explanation across different parts of the codebase, especially the overload! implementation and understanding of how overloads dispatch.

the code implementation are mine, written after studying forward_list, as i already have understanding of std::array specs from c++.

after studying forward_list and the use of &mut for c++ move, i want to ask if there have been any discussion about offering rust style move (by value)? i understand this would be a mismatch between both languages, but i curious for case when the moved-from c++ object itself needs not to be used after it is moved. because i initially implemented move to take ownership of the other object.

closes #34

  1. Write Rust wrappers for that C++ type, for 3-5 different overloaded method names:
    • Create a new file named after your type in overloading-macros/cpp-overload-test/src/stdcpp
    • Wrap constructors first, writing tests to make sure the correct constructor is called
    • Explain any potential compatibility issues in a Limitations doc section
    • Explain usability issues in an Ergonomics doc section
    • Check that you have implemented all the overloads for each method name, or documented why you can't
    • Push your changes and wait for a review
  2. Add a separate example with some failing overloads
    • Create a new file named after your type in overloading-macros/cpp-overload-test/examples
    • Wrap accessor/modifier methods
    • Explain how they fail in an Incompatibilities doc section
    • Explain how the overload failures could be resolved in a Workarounds doc section
    • Optional: If there's a C++ feature with no equivalent in Rust, explain that in an Inexpressible Overloads doc section
    • Push your changes and wait for a review
  3. Update the overload macro compatibility table Markdown doc
    • If you haven't checked some kinds of overloads, put a ?in those squares
    • Push your changes and wait for a review

Signed-off-by: Ikeh Chukwuka <mrikehchukwuka@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

array

1 participant