Header file destroy.hpp

#define SIPLASPLAS_UTILITY_DESTROY_HPP 

#include <type_traits>

namespace cpp
{
    template <typename T>
    void destroy(T& object);
    
    template <typename T>
    void destroy(T* objectPtr);
    
    template <typename R, typename ... Args>
    void destroy(R(*functionPointer)(Args...));
    
    template <typename T, typename ... Args>
    void construct(void* where, Args&&... args);
    
    template <typename T, typename ... Args>
    void construct(T* where, Args&&... args);
}

Function template cpp::construct<T, Args...>

template <typename T, typename ... Args>
void construct(void* where, Args&&... args);

This function performs an in-place construction of an object of type T in the given address. Arguments are passed as-is to the object constructor. The behavior is undefined if alignment(pointer) != alignof(T).

std::aligned_storage<std::string> storage;
cpp::construct<std::string>(&storage, "hello, world!");

Parameter cpp::construct::where

void* where

Location of the object \param args Constructor arguments


Function template cpp::construct<T, Args...>

template <typename T, typename ... Args>
void construct(T* where, Args&&... args);

This function performs an in-place construction of an object of type T in the given address. Arguments are passed as-is to the object constructor. The behavior is undefined if alignment(pointer) != alignof(T).

std::aligned_storage<std::string> storage;
std::string* stringPtr = reinterpret_cast<std::string*>(&storage);

cpp::construct(stringPtr, "hello, world!");

Parameter cpp::construct::where

T* where

Location of the object \param args Constructor arguments