2022-04-10 00:17:06 +00:00
|
|
|
#ifndef _RSTL_CONSTRUCT_HPP
|
|
|
|
#define _RSTL_CONSTRUCT_HPP
|
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
|
|
|
|
namespace rstl {
|
|
|
|
template < typename T >
|
|
|
|
inline void construct(void* dest, const T& src) {
|
2022-04-15 19:24:52 +00:00
|
|
|
new (dest) T(src);
|
2022-04-10 00:17:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template < typename T >
|
|
|
|
inline void destroy(T* in) {
|
|
|
|
in->~T();
|
|
|
|
}
|
2022-04-15 19:24:52 +00:00
|
|
|
// template < typename T >
|
|
|
|
// inline void destroy(const T* in) {}
|
2022-04-10 00:17:06 +00:00
|
|
|
|
|
|
|
template < typename Iter >
|
|
|
|
inline void destroy(Iter begin, Iter end) {
|
|
|
|
Iter current = begin;
|
|
|
|
while (current != end) {
|
|
|
|
current.destroy();
|
|
|
|
++current;
|
|
|
|
}
|
|
|
|
}
|
2022-04-15 19:24:52 +00:00
|
|
|
template < typename S >
|
|
|
|
inline void destroy(S* begin, S* end) {
|
|
|
|
S* current = begin;
|
|
|
|
while (current != end) {
|
|
|
|
destroy(current);
|
|
|
|
++current;
|
|
|
|
}
|
|
|
|
}
|
2022-04-10 00:17:06 +00:00
|
|
|
|
|
|
|
template < typename Iter, typename T >
|
2022-04-15 19:24:52 +00:00
|
|
|
inline void uninitialized_copy(Iter begin, Iter end, T* out) {
|
2022-04-10 00:17:06 +00:00
|
|
|
Iter current = begin;
|
|
|
|
while (current != end) {
|
2022-04-15 19:24:52 +00:00
|
|
|
construct(out, *current);
|
|
|
|
current.destroy();
|
|
|
|
++out;
|
2022-04-10 00:17:06 +00:00
|
|
|
++current;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-15 19:24:52 +00:00
|
|
|
template < typename S, typename D >
|
|
|
|
inline void uninitialized_copy(D* out, S* begin, S* end) {
|
|
|
|
while (begin != end) {
|
|
|
|
construct(out, *begin);
|
|
|
|
++out;
|
|
|
|
++begin;
|
|
|
|
}
|
|
|
|
// rstl::destroy(begin, end);
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME this is a hack around regalloc
|
|
|
|
// need to figure out the proper types/positions for all of these funcs
|
|
|
|
template < typename S, typename D >
|
|
|
|
inline void uninitialized_copy_2(S* begin, D* out, S* end) {
|
|
|
|
while (begin != end) {
|
|
|
|
construct(out, *begin);
|
|
|
|
++out;
|
|
|
|
++begin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-11 22:42:08 +00:00
|
|
|
template < typename S, typename D >
|
2022-09-13 04:26:54 +00:00
|
|
|
// inline void uninitialized_copy_n(S* src, int count, D* dest) {
|
2022-08-26 03:46:24 +00:00
|
|
|
inline void uninitialized_copy_n(D* dest, S* src, int count) {
|
|
|
|
for (int i = 0; i < count; ++dest, ++i, ++src) {
|
2022-04-10 00:17:06 +00:00
|
|
|
construct(dest, *src);
|
|
|
|
}
|
2022-04-11 22:42:08 +00:00
|
|
|
// destroy(src, src + count); ??
|
2022-04-10 00:17:06 +00:00
|
|
|
}
|
2022-08-13 01:26:00 +00:00
|
|
|
|
|
|
|
template < typename D, typename S >
|
|
|
|
inline void uninitialized_fill_n(D dest, int count, const S& value) {
|
|
|
|
for (int i = 0; i < count; ++dest, ++i) {
|
|
|
|
construct(dest, value);
|
|
|
|
}
|
|
|
|
}
|
2022-04-10 00:17:06 +00:00
|
|
|
} // namespace rstl
|
|
|
|
|
|
|
|
#endif
|