Closed gnzlbg closed 8 years ago
The section on default initialization:
Default initialization (possible future Extension) The size-modifying operations of the inline_vector that do not require a value also have the following analogous member functions that perform default initialization instead of value initialization: template <typename Value, std::size_t Capacity> struct inline_vector { // ... static constexpr inline_vector default_initialized(size_t n); constexpr void resize_default_initialized(size_type sz); constexpr void resize_unchecked_default_initialized(size_type sz); }; Alternatively, tag dispatching could be used.
Default initialization (possible future Extension)
The size-modifying operations of the inline_vector that do not require a value also have the following analogous member functions that perform default initialization instead of value initialization:
template <typename Value, std::size_t Capacity> struct inline_vector { // ... static constexpr inline_vector default_initialized(size_t n); constexpr void resize_default_initialized(size_type sz); constexpr void resize_unchecked_default_initialized(size_type sz); };
Alternatively, tag dispatching could be used.
prefers static member functions to tags, but tags are objectively better:
Using tags:
optional<inline_vector<T, Capacity>> ov { std::in_place, std::default_initialized, N };
the inline_vector can be constructed in place without involving a copy or move, but using a static member function:
inline_vector
optional<inline_vector<T, Capacity>> ov { std::in_place, inline_vector<T, Capacity>::default_initialized(N) };
will necessarily incur the cost of a move operation (which in particular for inline_vector will be often as expensive as a copy).
Thanks to @akrzemi1 for the discussion! (add to acknowledgements)
Closed by https://github.com/gnzlbg/inline_vector/commit/4d5aea12d87c49122f99c021f455fa17086f36ce .
The section on default initialization:
prefers static member functions to tags, but tags are objectively better:
Using tags:
the
inline_vector
can be constructed in place without involving a copy or move, but using a static member function:will necessarily incur the cost of a move operation (which in particular for
inline_vector
will be often as expensive as a copy).Thanks to @akrzemi1 for the discussion! (add to acknowledgements)