std.hpp
Go to the documentation of this file.
1 // Copyright (C) 2020-2024 Jonathan Müller and lexy contributors
2 // SPDX-License-Identifier: BSL-1.0
3 
4 #ifndef LEXY_DETAIL_STD_HPP_INCLUDED
5 #define LEXY_DETAIL_STD_HPP_INCLUDED
6 
8 
9 //=== iterator tags ===//
10 #if defined(__GLIBCXX__)
11 
12 namespace std
13 {
14 _GLIBCXX_BEGIN_NAMESPACE_VERSION
15 struct forward_iterator_tag;
16 struct bidirectional_iterator_tag;
17 _GLIBCXX_END_NAMESPACE_VERSION
18 } // namespace std
19 
20 #elif defined(_LIBCPP_VERSION)
21 
22 _LIBCPP_BEGIN_NAMESPACE_STD
23 struct forward_iterator_tag;
24 struct bidirectional_iterator_tag;
25 _LIBCPP_END_NAMESPACE_STD
26 
27 #else
28 
29 // Forward declaring things in std is not allowed, but I'm willing to take the risk.
30 
31 namespace std
32 {
33 struct forward_iterator_tag;
34 struct bidirectional_iterator_tag;
35 } // namespace std
36 
37 #endif
38 
39 //=== (constexpr) construct_at ===//
40 #if !LEXY_HAS_CONSTEXPR_DTOR
41 
42 namespace lexy::_detail
43 {
44 // We don't have constexpr dtor's, so this is just a regular function.
45 template <typename T, typename... Args>
46 T* construct_at(T* ptr, Args&&... args)
47 {
48  return ::new ((void*)ptr) T(LEXY_FWD(args)...);
49 }
50 } // namespace lexy::_detail
51 
52 #elif defined(_MSC_VER)
53 
54 namespace lexy::_detail
55 {
56 // MSVC can make it constexpr if marked with an attribute given by a macro.
57 template <typename T, typename... Args>
58 constexpr T* construct_at(T* ptr, Args&&... args)
59 {
60 # if defined(_MSVC_CONSTEXPR)
61  _MSVC_CONSTEXPR
62 # endif
63  return ::new ((void*)ptr) T(LEXY_FWD(args)...);
64 }
65 } // namespace lexy::_detail
66 
67 #else
68 
69 namespace lexy::_detail
70 {
71 struct _construct_at_tag
72 {};
73 } // namespace lexy::_detail
74 
75 namespace std
76 {
77 // GCC only allows constexpr placement new inside a function called `std::construct_at`.
78 // So we write our own.
79 template <typename T, typename... Args>
80 constexpr T* construct_at(lexy::_detail::_construct_at_tag, T* ptr, Args&&... args)
81 {
82  return ::new ((void*)ptr) T(LEXY_FWD(args)...);
83 }
84 } // namespace std
85 
86 namespace lexy::_detail
87 {
88 template <typename T, typename... Args>
89 constexpr T* construct_at(T* ptr, Args&&... args)
90 {
91  return std::construct_at(lexy::_detail::_construct_at_tag{}, ptr, LEXY_FWD(args)...);
92 }
93 } // namespace lexy::_detail
94 
95 #endif
96 
97 #endif // LEXY_DETAIL_STD_HPP_INCLUDED
98 
config.hpp
LEXY_FWD
#define LEXY_FWD(...)
Definition: config.hpp:30
lexy::_detail
Definition: any_ref.hpp:12
std
Definition: std.hpp:31
lexy::_detail::construct_at
T * construct_at(T *ptr, Args &&... args)
Definition: std.hpp:46


behaviortree_cpp_v4
Author(s): Davide Faconti
autogenerated on Fri Dec 13 2024 03:19:17