StormByte C++ Library 0.0.9999
StormByte is a comprehensive, cross-platform C++ library aimed at easing system programming, configuration management, logging, and database handling tasks. This library provides a unified API that abstracts away the complexities and inconsistencies of different platforms (Windows, Linux).
Loading...
Searching...
No Matches
clonable.hxx
1#pragma once
2
3#include <concepts>
4#include <memory>
5
13namespace StormByte {
19 template<typename SmartPointer, typename T>
21 std::same_as<SmartPointer, std::shared_ptr<T>> ||
22 std::same_as<SmartPointer, std::unique_ptr<T>>;
23
28 template<class T, typename SmartPointer = std::shared_ptr<T>>
30 public:
31 using PointerType = SmartPointer;
39 template<class Target, typename... Args>
40 static PointerType MakePointer(Args&&... args) {
41 if constexpr (std::is_same_v<PointerType, std::shared_ptr<T>>) {
42 return std::make_shared<Target>(std::forward<Args>(args)...);
43 } else if constexpr (std::is_same_v<PointerType, std::unique_ptr<T>>) {
44 return std::make_unique<Target>(std::forward<Args>(args)...);
45 } else {
46 static_assert(false, "Unsupported smart pointer type");
47 }
48 }
49
53 constexpr Clonable() = default;
54
58 constexpr Clonable(const Clonable&) = default;
59
63 constexpr Clonable(Clonable&&) noexcept = default;
64
68 constexpr Clonable& operator=(const Clonable&) = default;
69
73 constexpr Clonable& operator=(Clonable&&) noexcept = default;
74
78 virtual constexpr ~Clonable() noexcept = default;
79
84 virtual PointerType Clone() const = 0;
85
90 virtual PointerType Move() = 0;
91 };
92}
A class that can be cloned.
Definition clonable.hxx:29
static PointerType MakePointer(Args &&... args)
Definition clonable.hxx:40
constexpr Clonable(const Clonable &)=default
virtual PointerType Clone() const =0
virtual PointerType Move()=0
constexpr Clonable()=default
constexpr Clonable(Clonable &&) noexcept=default
SmartPointer PointerType
Pointer type.
Definition clonable.hxx:31
Concept to check if a type is a valid smart pointer.
Definition clonable.hxx:20
Main namespace for the StormByte library.