Home » U++ Library support » U++ Core » Doubt with Buffer<> of a trivially destructible type
Re: Doubt with Buffer<> of a trivially destructible type [message #61243 is a reply to message #61224] |
Sat, 14 December 2024 19:19   |
Lance
Messages: 656 Registered: March 2007
|
Contributor |
|
|
This is a valid use case, and something need to be addressed in u++ libary directly instead of circling around.
Here is a simple utility we can use to fix it from with u++ libary
template <typename T, std::size_t...>
constexpr auto object_count(T& t)
{
return 1u;
}
template <std::size_t ... Ns, typename T, std::size_t n>
constexpr auto object_count(T (&arr)[n] )
{
return n * object_count(arr[0]);
}
// eg, with
double d;
double a1[5];
double a2[5][3];
double a3[5][4][2];
// then
static_assert(object_count(d)==1,"?");
static_assert(object_count(a1)==5,"?");
static_assert(object_count(a2)==15,"?");
static_assert(object_count(d3)==40,"?);
With above utility, we can easily modify u++ Vector to accomodate c style array.
basially, if T is trivially relocatible, then
any c array of T is alos trivially relocatible,
Upp::Vector don't care any detail of c array, except the total number of T objects in the array to properly construct, move and destruct it, with T::~T() properly defined of course.
Oh, for
// some type T
T d3[3][2][5];
a simple
will do the job
|
|
|
 |
|
Doubt with Buffer<> of a trivially destructible type
By: koldo on Thu, 12 December 2024 12:58
|
 |
|
Re: Doubt with Buffer<> of a trivially destructible type
By: Oblivion on Thu, 12 December 2024 14:15
|
 |
|
Re: Doubt with Buffer<> of a trivially destructible type
By: Oblivion on Thu, 12 December 2024 14:40
|
 |
|
Re: Doubt with Buffer<> of a trivially destructible type
By: koldo on Thu, 12 December 2024 16:05
|
 |
|
Re: Doubt with Buffer<> of a trivially destructible type
By: Lance on Sat, 14 December 2024 19:19
|
 |
|
Re: Doubt with Buffer<> of a trivially destructible type
By: koldo on Sat, 14 December 2024 20:45
|
 |
|
Re: Doubt with Buffer<> of a trivially destructible type
By: Lance on Sat, 14 December 2024 20:53
|
 |
|
Re: Doubt with Buffer<> of a trivially destructible type
By: Lance on Sat, 14 December 2024 21:02
|
 |
|
Re: Doubt with Buffer<> of a trivially destructible type
By: Lance on Sat, 14 December 2024 21:37
|
 |
|
Re: Doubt with Buffer<> of a trivially destructible type
By: koldo on Sun, 15 December 2024 12:25
|
 |
|
Re: Doubt with Buffer<> of a trivially destructible type
By: koldo on Sun, 15 December 2024 12:45
|
 |
|
Re: Doubt with Buffer<> of a trivially destructible type
By: Lance on Sun, 15 December 2024 14:29
|
 |
|
Re: Doubt with Buffer<> of a trivially destructible type
By: mirek on Thu, 26 December 2024 18:47
|
 |
|
Re: Doubt with Buffer<> of a trivially destructible type
By: koldo on Fri, 27 December 2024 18:34
|
Goto Forum:
Current Time: Fri Jun 06 09:09:09 CEST 2025
Total time taken to generate the page: 0.04519 seconds
|