tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
construct_at.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_MEMORY_CONSTRUCT_AT_HPP
4#define TETL_MEMORY_CONSTRUCT_AT_HPP
5
6#include <etl/_config/all.hpp>
7
11
12#if __has_include(<memory>)
13 // TODO: Only include private header that defines construct_at from each STL
14 // STL = https://github.com/microsoft/STL/blob/main/stl/inc/xutility
15 // libc++ = https://github.com/llvm/llvm-project/blob/main/libcxx/include/__memory/construct_at.h
16 // libstdc++ = https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/bits/stl_construct.h
17 #include <memory>
18#else
19// NOLINTBEGIN
20
21namespace std {
22
23template <typename T, typename... Args, typename = decltype(::new(etl::declval<void*>()) T(etl::declval<Args>()...))>
24constexpr auto construct_at(T* p, Args&&... args) -> T*
25{
26 return ::new (static_cast<void*>(p)) T(etl::forward<Args>(args)...);
27}
28
29} // namespace std
30
31// NOLINTEND
32#endif
33
34namespace etl {
35
37template <typename T, typename... Args, typename = decltype(::new(etl::declval<void*>()) T(etl::declval<Args>()...))>
38constexpr auto construct_at(T* p, Args&&... args) -> T*
39{
40 return ::std::construct_at(p, etl::forward<Args>(args)...);
41}
42
43} // namespace etl
44
45#endif // TETL_MEMORY_CONSTRUCT_AT_HPP
Definition adjacent_find.hpp:8
auto declval() noexcept -> add_rvalue_reference_t< T >
constexpr auto construct_at(T *p, Args &&... args) -> T *
Creates a T object initialized with arguments args... at given address p.
Definition construct_at.hpp:38
constexpr auto forward(remove_reference_t< T > &param) noexcept -> T &&
Forwards lvalues as either lvalues or as rvalues, depending on T. When t is a forwarding reference (a...
Definition forward.hpp:18