Skip to content

feat: improve the code sample for std::inplace_vector#73

Open
YukunJ wants to merge 1 commit into
Awesome-Embedded-Learning-Studio:mainfrom
YukunJ:improve_inplace_vector
Open

feat: improve the code sample for std::inplace_vector#73
YukunJ wants to merge 1 commit into
Awesome-Embedded-Learning-Studio:mainfrom
YukunJ:improve_inplace_vector

Conversation

@YukunJ

@YukunJ YukunJ commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Brief: improve the code sample for std::inplace_vector section.

Since the tutorial is explicitly mentioning

a.

最讨喜的一个性质是:T 是 trivially copyable 时,inplace_vector<T, N> 本身也是 trivially copyable
doc: https://cppreference.com/cpp/container/inplace_vector/try_push_back

b.

容量超限时的行为也设计得克制:push_back 超过 N 会抛 std::bad_alloc(异常关闭时退化为 terminate),而想避免异常可以用 C++26 的 try_push_back/try_emplace_back,它们超限时不抛、返回一个错误指示,适合 -fno-exceptions 环境。

It's worthwhile to show these two points in the code sample.

QA:
see godbolt link https://godbolt.org/z/K78EnTnYM

@Charliechen114514

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant