2022-10-09 01:13:17 -04:00
|
|
|
#ifndef _RSTL_CONSTRUCT
|
|
|
|
|
#define _RSTL_CONSTRUCT
|
2022-04-09 20:17:06 -04:00
|
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
|
|
2022-10-14 15:20:36 +03:00
|
|
|
#include "Kyoto/Alloc/CMemory.hpp"
|
|
|
|
|
|
2022-04-09 20:17:06 -04:00
|
|
|
namespace rstl {
|
|
|
|
|
template < typename T >
|
2026-03-17 00:10:26 -06:00
|
|
|
static inline void construct(void* dest, const T& src) {
|
2022-04-15 15:24:52 -04:00
|
|
|
new (dest) T(src);
|
2022-04-09 20:17:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template < typename T >
|
2026-03-17 00:10:26 -06:00
|
|
|
static inline void destroy(T* in) {
|
2022-04-09 20:17:06 -04:00
|
|
|
in->~T();
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-03 20:00:46 -04:00
|
|
|
template < typename It >
|
2026-03-17 00:10:26 -06:00
|
|
|
static inline void destroy(It begin, It end) {
|
2022-10-03 20:00:46 -04:00
|
|
|
It cur = begin;
|
|
|
|
|
for (; cur != end; ++cur) {
|
|
|
|
|
destroy(&*cur);
|
2022-04-15 15:24:52 -04:00
|
|
|
}
|
|
|
|
|
}
|
2022-04-09 20:17:06 -04:00
|
|
|
|
2022-10-03 20:00:46 -04:00
|
|
|
template < typename It, typename T >
|
2026-03-17 00:10:26 -06:00
|
|
|
static inline T uninitialized_copy(It begin, It end, T out) {
|
|
|
|
|
T tmp = out;
|
2022-10-03 20:00:46 -04:00
|
|
|
It cur = begin;
|
2026-01-24 12:40:49 -08:00
|
|
|
for (; cur != end; ++tmp, ++cur) {
|
|
|
|
|
construct(tmp, *cur);
|
2022-04-09 20:17:06 -04:00
|
|
|
}
|
2026-01-15 23:18:45 -08:00
|
|
|
|
2026-01-24 12:40:49 -08:00
|
|
|
return tmp;
|
2022-04-09 20:17:06 -04:00
|
|
|
}
|
|
|
|
|
|
2022-04-15 15:24:52 -04:00
|
|
|
template < typename S, typename D >
|
2026-03-17 00:10:26 -06:00
|
|
|
static inline void uninitialized_copy_n(S src, int n, D dest) {
|
2022-10-03 20:00:46 -04:00
|
|
|
D cur = dest;
|
|
|
|
|
for (int i = 0; i < n; ++cur, ++i, ++src) {
|
|
|
|
|
construct(&*cur, *src);
|
2022-04-15 15:24:52 -04:00
|
|
|
}
|
2022-04-09 20:17:06 -04:00
|
|
|
}
|
2022-08-12 21:26:00 -04:00
|
|
|
|
|
|
|
|
template < typename D, typename S >
|
2026-03-17 00:10:26 -06:00
|
|
|
static inline void uninitialized_fill_n(D dest, int n, const S& value) {
|
2022-10-03 20:00:46 -04:00
|
|
|
D cur = dest;
|
2022-10-11 00:00:52 -04:00
|
|
|
for (int i = 0; i < n; ++i, ++cur) {
|
2022-10-03 20:00:46 -04:00
|
|
|
construct(&*cur, value);
|
2022-08-12 21:26:00 -04:00
|
|
|
}
|
|
|
|
|
}
|
2022-04-09 20:17:06 -04:00
|
|
|
} // namespace rstl
|
|
|
|
|
|
2022-10-09 01:13:17 -04:00
|
|
|
#endif // _RSTL_CONSTRUCT
|