-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
139 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
flux-foundation/flux/foundation/containers/detail/temp_value.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#pragma once | ||
|
||
namespace flux::fou::detail { | ||
|
||
// clang-format off | ||
template <typename T, typename Allocator> | ||
struct temp_value final { | ||
using allocator_traits = allocator_traits<Allocator>; | ||
|
||
union { | ||
T value; | ||
}; | ||
Allocator& allocator; | ||
|
||
template <typename... Args> | ||
FLUX_NO_CFI constexpr explicit temp_value(Allocator& alloc, Args&&... args) noexcept | ||
: allocator(alloc) { | ||
construct_at(addressof(value), ::std::forward<Args>(args)...); | ||
} | ||
|
||
temp_value(temp_value const&) = delete; | ||
temp_value& operator=(temp_value const&) = delete; | ||
|
||
constexpr ~temp_value() requires meta::trivially_destructible<T> = default; | ||
constexpr ~temp_value() { destroy_at(addressof(value)); } | ||
|
||
constexpr T& get() noexcept { | ||
return value; | ||
} | ||
|
||
constexpr T const& get() const noexcept { | ||
return value; | ||
} | ||
}; | ||
// clang-format on | ||
|
||
} // namespace flux::fou::detail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters