VCCC  2024.05
VisualCamp Common C++ library
construct_at.hpp
Go to the documentation of this file.
1 //
2 // Created by YongGyu Lee on 3/20/24.
3 //
4 
5 #ifndef VCCC_MEMORY_CONSTRUCT_AT_HPP_
6 #define VCCC_MEMORY_CONSTRUCT_AT_HPP_
7 
8 #include <new>
9 #include <type_traits>
10 
13 
14 namespace vccc {
15 namespace detail {
16 
17 template<typename T, typename ArgPack, typename = void>
18 struct in_place_constructible_impl : std::false_type {};
19 
20 template<typename T, typename... Args>
21 struct in_place_constructible_impl<T, type_sequence<Args...>,
22  void_t<decltype(::new(std::declval<void*>()) T(std::declval<Args>()...))>> : std::true_type {};
23 
24 template<typename T, typename... Args>
25 struct in_place_constructible
26  : in_place_constructible_impl<T, type_sequence<Args...>> {};
27 
28 } // namespace detail
29 
32 
33 template<typename T, typename... Args, std::enable_if_t<detail::in_place_constructible<T, Args...>::value, int> = 0>
34 constexpr T* construct_at(T* p, Args&&... args) noexcept(std::is_nothrow_constructible<T, Args...>::value) {
35  return ::new (static_cast<void*>(p)) T(std::forward<Args>(args)...);
36 }
37 
39 
40 } // namespace vccc
41 
42 #endif // VCCC_MEMORY_CONSTRUCT_AT_HPP_
constexpr T * construct_at(T *p, Args &&... args) noexcept(std::is_nothrow_constructible< T, Args... >::value)
Definition: construct_at.hpp:34
void void_t
Definition: void_t.hpp:19
Definition: directory.h:12
constexpr VCCC_INLINE_OR_STATIC detail::element_niebloid< 1 > value
Definition: key_value.hpp:35