prime/include/rstl/construct.hpp

53 lines
1.0 KiB
C++
Raw Permalink Normal View History

#ifndef _RSTL_CONSTRUCT
#define _RSTL_CONSTRUCT
#include "types.h"
2022-10-14 12:20:36 +00:00
#include "Kyoto/Alloc/CMemory.hpp"
namespace rstl {
template < typename T >
inline void construct(void* dest, const T& src) {
new (dest) T(src);
}
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-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-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-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-11 04:00:52 +00:00
for (int 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
}
}
} // namespace rstl
#endif // _RSTL_CONSTRUCT