/*
 * Copyright (C) 2020-2021 Aloysius Indrayanto
 *
 * This file is part of the eCxx library, see LICENSE file for the license details.
 */


#ifndef ECXX_CTL_DEFAULT_DELETER_H
#define ECXX_CTL_DEFAULT_DELETER_H


#include "Types.h"


//
// Uncomment this to enable default-deleter debugging
// (the system-wide debugging macro must be enabled for it to have any effect)
//
// #define DEFAULT_DELETER_DEBUG(FMT, ...) SYSTEM_DEBUG("DefaultDeleter::ValueT " FMT, ## __VA_ARGS__)

#ifndef DEFAULT_DELETER_DEBUG
    #define NO_DEFAULT_DELETER_DEBUG
    #define DEFAULT_DELETER_DEBUG(FMT, ...) SYSTEM_DEBUG_NOP
#endif


namespace eCxx {

namespace Ext {


//
// Default deleters
//
template <typename ValueT>
struct DefaultDeleter {
    inline void operator()(ValueT* ptr) const
    {
        DEFAULT_DELETER_DEBUG("(%p)\n", ptr);
        delete ptr;
    }
};


template <typename ValueT>
struct DefaultDeleter<ValueT[]> {
    inline void operator()(ValueT* ptr) const
    {
        DEFAULT_DELETER_DEBUG("[](%p)\n", ptr);
        delete [] ptr;
    }
};


} // namespace Ext

} // namespace eCxx


#endif
