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:
39 template<class Target, typename... 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
64
69
74
79
85
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.
std::conditional_t< is_reference< T >::value, std::expected< std::reference_wrapper< std::remove_reference_t< T > >, std::shared_ptr< E > >, std::expected< T, std::shared_ptr< E > > > Expected
Expected type with support for reference types.
Definition expected.hxx:32