1#ifndef ORIGINAL_OPTIONAL_H
2#define ORIGINAL_OPTIONAL_H
61 template<
typename TYPE>
81 storage(
const storage&
other)
noexcept =
default;
84 storage& operator=(
const storage&
other)
noexcept =
default;
99 void destroy()
noexcept;
114 template<
typename...
Args>
199 void reset()
noexcept;
207 template<
typename...
Args>
243 explicit operator bool()
const;
279 bool has_value_ =
false;
419 template<
typename TYPE>
422template<
typename TYPE>
425 new(&this->none_)
none{};
428template<
typename TYPE>
431template<
typename TYPE>
433 if (this->non_none_type_){
434 this->val_.type_.~TYPE();
435 this->non_none_type_ =
false;
437 this->val_.none_.~none();
438 this->non_none_type_ =
true;
442template<
typename TYPE>
444 : non_none_type_(
false), val_() {}
446template<
typename TYPE>
447template<
typename...
Args>
449 : non_none_type_(
true), val_() {
450 new (&this->val_.type_)
TYPE{ std::forward<Args>(
args)... };
453template<
typename TYPE>
455 this->non_none_type_ =
other.non_none_type_;
456 if (
other.non_none_type_) {
457 new (&val_.type_)
TYPE{
other.val_.type_ };
459 new (&val_.none_)
none{};
463template<
typename TYPE>
470 this->non_none_type_ =
other.non_none_type_;
471 if (
other.non_none_type_) {
472 new (&val_.type_)
TYPE{
other.val_.type_ };
474 new (&val_.none_)
none{};
479template<
typename TYPE>
481 this->non_none_type_ =
other.non_none_type_;
482 if (this->non_none_type_){
483 new (&val_.type_)
TYPE{ std::move(
other.val_.type_) };
485 new (&val_.none_)
none{};
489template<
typename TYPE>
496 this->non_none_type_ =
other.non_none_type_;
497 if (this->non_none_type_){
498 new (&val_.type_)
TYPE{ std::move(
other.val_.type_) };
500 new (&val_.none_)
none{};
505template <
typename TYPE>
515template<
typename TYPE>
518 if (!this->non_none_type_)
519 throw valueError(
"Dereferencing a original::none value");
521 return this->val_.type_;
524template<
typename TYPE>
527 if (!this->non_none_type_)
528 throw valueError(
"Dereferencing a original::none value");
530 return this->val_.type_;
533template<
typename TYPE>
536 if (!this->non_none_type_)
537 throw valueError(
"Accessing member of a original::none value");
539 return &this->val_.type_;
542template<
typename TYPE>
545 if (!this->non_none_type_)
546 throw valueError(
"Accessing member of a original::none value");
548 return &this->val_.type_;
551template<
typename TYPE>
553 return this->non_none_type_ ? &this->val_.type_ :
nullptr;
556template<
typename TYPE>
558 return this->non_none_type_ ? &this->val_.type_ :
nullptr;
561template<
typename TYPE>
566template<
typename TYPE>
567template<
typename...
Args>
570 this->non_none_type_ =
true;
571 new (&val_.type_)
TYPE{ std::forward<Args>(
args)... };
574template<
typename TYPE>
577 this->non_none_type_ =
true;
578 new (&val_.type_)
TYPE{
t };
581template <
typename TYPE>
589template<
typename TYPE>
591 return this->non_none_type_;
594template <
typename TYPE>
597 return this->
operator bool();
600template<
typename TYPE>
613 this->has_value_ =
true;
632 this->has_value_ =
false;
637 return this->has_value_;
642 return this->has_value_;
647 this->has_value_ =
other.has_value_;
648 other.has_value_ =
false;
657 this->has_value_ =
other.has_value_;
658 other.has_value_ =
false;
670template <
typename TYPE>
alternative()
Constructs an empty alternative<void>
A type-safe container that may or may not contain a value.
Definition optional.h:62
void set(const TYPE &t)
Sets value by copy.
Definition optional.h:575
alternative()
Constructs an empty alternative.
Definition optional.h:443
void emplace(Args &&... args)
Constructs value in-place.
Definition optional.h:568
bool hasValue() const
Checks if contains a value.
Definition optional.h:595
void reset() noexcept
Resets to empty state.
Definition optional.h:562
alternative & operator=(const alternative &other)
Copy assignment.
Definition optional.h:465
const TYPE * get() const
Gets const pointer to value.
Definition optional.h:552
~alternative()
Destructor.
Definition optional.h:601
const TYPE & operator*() const
Const value access.
Definition optional.h:517
const TYPE * operator->() const
Const member access.
Definition optional.h:535
void swap(alternative &other) noexcept
Swaps contents with another alternative.
Definition optional.h:506
void swap(autoPtr &other) noexcept
Swaps the reference counters between two autoPtr instances.
Definition autoPtr.h:703
A placeholder type representing the absence of a value.
Definition types.h:33
Unique ownership smart pointer with move semantics.
Definition ownerPtr.h:37
Abstract base class for unique element containers.
Definition set.h:44
Exception for invalid parameter values.
Definition error.h:219
Custom exception classes and callback validation utilities.
Main namespace for the project Original.
Definition algorithms.h:21
Standard namespace extensions for original::alternative.
Definition allocator.h:351
void swap(original::objPoolAllocator< TYPE > &lhs, original::objPoolAllocator< TYPE > &rhs) noexcept
Specialization of std::swap for objPoolAllocator.
Definition allocator.h:635
Core type system foundations and concept definitions.