Page MenuHomePhorge

copy-helper.hpp
No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None

copy-helper.hpp

/*
* This file is part of libkazv.
* SPDX-FileCopyrightText: 2020-2021 Tusooa Zhu <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#pragma once
#include "libkazv-config.hpp"
#define KAZV_DECLARE_COPYABLE(typeName) \
typeName(const typeName &that); \
typeName(typeName &&that); \
typeName &operator=(const typeName &that); \
typeName &operator=(typeName &&that);
#define KAZV_DEFINE_COPYABLE_UNIQUE_PTR(typeName, privateName) \
typeName::typeName(const typeName &that) \
: privateName(std::make_unique<decltype(privateName)::element_type>(*(that.privateName))) \
{ \
} \
typeName::typeName(typeName &&that) \
: privateName(std::move(that.privateName)) \
{ \
} \
typeName &typeName::operator=(const typeName &that) \
{ \
if (privateName != that.privateName) { \
privateName.reset(); \
privateName = std::make_unique<decltype(privateName)::element_type>(*(that.privateName)); \
} \
return *this; \
} \
typeName &typeName::operator=(typeName &&that) \
{ \
if (privateName != that.privateName) { \
privateName.reset(); \
privateName = std::move(that.privateName); \
} \
return *this; \
}

File Metadata

Mime Type
text/x-c
Expires
Sun, Dec 1, 6:40 PM (1 d, 16 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41796
Default Alt Text
copy-helper.hpp (2 KB)

Event Timeline