Skip to content

Commit

Permalink
Fixed: emplace_back would not return a reference
Browse files Browse the repository at this point in the history
Fixed: call_ctor not working with braces initialization
  • Loading branch information
richardbiely committed Mar 19, 2024
1 parent bc03d08 commit 1e1d22a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion include/gaia/cnt/impl/darray_ext_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ namespace gaia {
}

template <typename... Args>
auto emplace_back(Args&&... args) {
decltype(auto) emplace_back(Args&&... args) {
try_grow();

if constexpr (mem::is_soa_layout_v<T>) {
Expand Down
2 changes: 1 addition & 1 deletion include/gaia/cnt/impl/darray_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ namespace gaia {
}

template <typename... Args>
auto emplace_back(Args&&... args) {
decltype(auto) emplace_back(Args&&... args) {
try_grow();

if constexpr (mem::is_soa_layout_v<T>) {
Expand Down
2 changes: 1 addition & 1 deletion include/gaia/cnt/impl/sarray_ext_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ namespace gaia {
}

template <typename... Args>
constexpr auto emplace_back(Args&&... args) {
constexpr decltype(auto) emplace_back(Args&&... args) {
GAIA_ASSERT(size() < N);

if constexpr (mem::is_soa_layout_v<T>) {
Expand Down
5 changes: 4 additions & 1 deletion include/gaia/core/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ namespace gaia {
template <typename T, typename... Args>
void call_ctor(T* pData, Args&&... args) {
GAIA_ASSERT(pData != nullptr);
(void)::new (pData) T(GAIA_FWD(args)...);
if constexpr (std::is_constructible_v<T, Args...>)
(void)::new (pData) T(GAIA_FWD(args)...);
else
(void)::new (pData) T{GAIA_FWD(args)...};
}

//! Constructs an object of type \tparam T at the memory address \param pData.
Expand Down

0 comments on commit 1e1d22a

Please sign in to comment.