Date: Sun, 3 Sep 2023 01:41:45 +0000
I am talking about consteval context. See
Portable-Cpp-Guideline/README.md at main · trcrsired/Portable-Cpp-Guideline (github.com)<https://github.com/trcrsired/Portable-Cpp-Guideline/blob/main/README.md>
Also see explanations:
https://youtu.be/OZxP5D8UiZ4?si=CGym2iIoUHLc1hnW&t=917
void * my_some_allocate(::std::size_t n) noexcept;
void * my_some_deallocate(void* ptr,::std::size_t n) noexcept;
constexpr void* my_some_allocate_constexpr(::std::size_t n) noexcept
{
if consteval
{
return ::operator new(n); // DOES NOT WORK!!
}
else
{
return my_some_allocate(n);
}
}
constexpr void* my_some_allocate_constexpr(void* ptr,::std::size_t n) noexcept
{
if consteval
{
return ::operator delete(n); // DOES NOT WORK!!
}
else
{
return my_some_deallocate(ptr,n);
}
}
template<typename T>
constexpr void* my_some_allocate_type_constexpr(::std::size_t n) noexcept
{
if consteval
{
return ::std::allocator<T>::allocate(n); // works but NOT freestanding!!
}
else
{
return my_some_allocate(n*sizeof(T));
}
}
template<typename T>
constexpr void my_some_allocate_type_constexpr(T *ptr,::std::size_t n) noexcept
{
if consteval
{
return ::std::allocator<T>::deallocate(ptr,n); // works but NOT freestanding!!
}
else
{
return my_some_deallocate(ptr,n*sizeof(T));
}
}
template<typename T>
constexpr void* my_some_allocate_type_constexpr2(::std::size_t n) noexcept
{
if consteval
{
return static_cast<T>(::operator new(n*sizeof(T))); // Not working
}
else
{
return my_some_allocate(n*sizeof(T));
}
}
template<typename T>
constexpr void my_some_allocate_type_constexpr2(T *ptr,::std::size_t n) noexcept
{
if consteval
{
::operator delete(ptr,n*sizeof(T)); // Not working
}
else
{
my_some_deallocate(ptr,n*sizeof(T));
}
}
/*
https://github.com/microsoft/STL/issues/4002
*/
Regarding std::addressof:
Prior to C++23, std::addressof was unavailable, implying that obtaining the address of an object within a freestanding constexpr context was not possible.
Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows
Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows
From: trtaab trtaab<mailto:tvfvof_at_[hidden]>
Sent: Saturday, September 2, 2023 15:35
To: std-proposals_at_[hidden]<mailto:std-proposals_at_[hidden]>
Subject: RE: PR: std::allocator<T>::allocate is not freestanding
BTW:
::std::allocator_traits<T>::allocate with a hint has the same issues too.
Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows
From: trtaab trtaab<mailto:tvfvof_at_[hidden]>
Sent: Saturday, September 2, 2023 15:22
To: std-proposals_at_[hidden]<mailto:std-proposals_at_[hidden]>
Subject: PR: std::allocator<T>::allocate is not freestanding
Currently there is no way to allocate memory at constexpr context in freestanding environment. This desperately needs a fix.
N4958 does not mark std::allocator<T> as freestanding so there is no way to allocate memory in freestanding.
This is std::addressof situation 2.0
Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows
Portable-Cpp-Guideline/README.md at main · trcrsired/Portable-Cpp-Guideline (github.com)<https://github.com/trcrsired/Portable-Cpp-Guideline/blob/main/README.md>
Also see explanations:
https://youtu.be/OZxP5D8UiZ4?si=CGym2iIoUHLc1hnW&t=917
void * my_some_allocate(::std::size_t n) noexcept;
void * my_some_deallocate(void* ptr,::std::size_t n) noexcept;
constexpr void* my_some_allocate_constexpr(::std::size_t n) noexcept
{
if consteval
{
return ::operator new(n); // DOES NOT WORK!!
}
else
{
return my_some_allocate(n);
}
}
constexpr void* my_some_allocate_constexpr(void* ptr,::std::size_t n) noexcept
{
if consteval
{
return ::operator delete(n); // DOES NOT WORK!!
}
else
{
return my_some_deallocate(ptr,n);
}
}
template<typename T>
constexpr void* my_some_allocate_type_constexpr(::std::size_t n) noexcept
{
if consteval
{
return ::std::allocator<T>::allocate(n); // works but NOT freestanding!!
}
else
{
return my_some_allocate(n*sizeof(T));
}
}
template<typename T>
constexpr void my_some_allocate_type_constexpr(T *ptr,::std::size_t n) noexcept
{
if consteval
{
return ::std::allocator<T>::deallocate(ptr,n); // works but NOT freestanding!!
}
else
{
return my_some_deallocate(ptr,n*sizeof(T));
}
}
template<typename T>
constexpr void* my_some_allocate_type_constexpr2(::std::size_t n) noexcept
{
if consteval
{
return static_cast<T>(::operator new(n*sizeof(T))); // Not working
}
else
{
return my_some_allocate(n*sizeof(T));
}
}
template<typename T>
constexpr void my_some_allocate_type_constexpr2(T *ptr,::std::size_t n) noexcept
{
if consteval
{
::operator delete(ptr,n*sizeof(T)); // Not working
}
else
{
my_some_deallocate(ptr,n*sizeof(T));
}
}
/*
https://github.com/microsoft/STL/issues/4002
*/
Regarding std::addressof:
Prior to C++23, std::addressof was unavailable, implying that obtaining the address of an object within a freestanding constexpr context was not possible.
Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows
Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows
From: trtaab trtaab<mailto:tvfvof_at_[hidden]>
Sent: Saturday, September 2, 2023 15:35
To: std-proposals_at_[hidden]<mailto:std-proposals_at_[hidden]>
Subject: RE: PR: std::allocator<T>::allocate is not freestanding
BTW:
::std::allocator_traits<T>::allocate with a hint has the same issues too.
Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows
From: trtaab trtaab<mailto:tvfvof_at_[hidden]>
Sent: Saturday, September 2, 2023 15:22
To: std-proposals_at_[hidden]<mailto:std-proposals_at_[hidden]>
Subject: PR: std::allocator<T>::allocate is not freestanding
Currently there is no way to allocate memory at constexpr context in freestanding environment. This desperately needs a fix.
N4958 does not mark std::allocator<T> as freestanding so there is no way to allocate memory in freestanding.
This is std::addressof situation 2.0
Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows
Received on 2023-09-03 01:41:50