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-10-04 00:00:46 +00:00
|
|
|
template < typename It >
|
|
|
|
inline void destroy(It begin, It end) {
|
|
|
|
It cur = begin;
|
|
|
|
for (; cur != end; ++cur) {
|
|
|
|
destroy(&*cur);
|
2022-04-10 00:17:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-04 00:00:46 +00:00
|
|
|
template < typename It, typename T >
|
|
|
|
inline void uninitialized_copy(It begin, It end, T* out) {
|
|
|
|
It cur = begin;
|
|
|
|
for (; cur != end; ++out, ++cur) {
|
|
|
|
construct(out, *cur);
|
2022-04-15 19:24:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-11 22:42:08 +00:00
|
|
|
template < typename S, typename D >
|
2022-10-04 00:00:46 +00:00
|
|
|
inline void uninitialized_copy_n(S src, int n, D dest) {
|
|
|
|
D cur = dest;
|
|
|
|
for (int i = 0; i < n; ++cur, ++i, ++src) {
|
|
|
|
construct(&*cur, *src);
|
2022-04-10 00:17:06 +00:00
|
|
|
}
|
|
|
|
}
|
2022-08-13 01:26:00 +00:00
|
|
|
|
|
|
|
template < typename D, typename S >
|
2022-10-04 00:00:46 +00:00
|
|
|
inline void uninitialized_fill_n(D dest, int n, const S& value) {
|
|
|
|
D cur = dest;
|
2022-10-06 12:51:36 +00:00
|
|
|
for (size_t i = 0; i < n ; ++i, ++cur) {
|
2022-10-04 00:00:46 +00:00
|
|
|
construct(&*cur, value);
|
2022-08-13 01:26:00 +00:00
|
|
|
}
|
|
|
|
}
|
2022-04-10 00:17:06 +00:00
|
|
|
} // namespace rstl
|
|
|
|
|
|
|
|
#endif
|