kblib 0.2.3
General utilities library for modern C++
|
Inline polymorphic object. Generally mimics the interfaces of std::optional and std::variant. More...
#include <kblib/poly_obj.h>
Public Types | |
using | base_type = Obj |
using | traits_type = Traits |
Static Public Attributes | |
static constexpr std::size_t | capacity = Capacity > 0 ? Capacity : Traits::default_capacity |
Equal to Capacity if specified, else Traits::default_capacity. More... | |
Related Functions | |
(Note that these are not member functions.) | |
template<typename T , typename D = T, std::size_t Capacity = sizeof(D), typename Traits = poly_obj_traits<T>, typename... Args> | |
auto | make_poly_obj (Args &&... args, std::nullptr_t=poly_warn_if<(Capacity !=sizeof(D) and Capacity > Traits::default_capacity)>()) -> poly_obj< T, std::max(Capacity, Traits::default_capacity), Traits > |
A convenience factory for making poly_objs. More... | |
Object Access | |
These functions allow access to the contained value. | |
auto | operator* () &noexcept -> Obj & |
Returns a reference to the contained object. More... | |
auto | operator* () const &noexcept -> const Obj & |
Returns a reference to the contained object. More... | |
auto | operator* () &&noexcept(Traits::nothrow_movable) -> Obj && |
Returns a reference to the contained object. More... | |
auto | operator* () const &&noexcept(Traits::nothrow_movable) -> const Obj && |
Returns a reference to the contained object. More... | |
auto | get () &noexcept -> Obj * |
Returns a pointer to the contained object. More... | |
auto | get () const &noexcept -> const Obj * |
Returns a pointer to the contained object. More... | |
auto | operator-> () &noexcept -> Obj * |
Returns a pointer to the contained object. More... | |
auto | operator-> () const &noexcept -> const Obj * |
Returns a pointer to the contained object. More... | |
template<typename... Args> | |
auto | operator() (Args &&... args) noexcept(is_nothrow_invocable< Obj &, Args &&... >::value) -> fakestd::invoke_result_t< Obj &, Args &&... > |
Invokes the contained function object, if Obj is a callable type. More... | |
template<typename... Args> | |
auto | operator() (Args &&... args) const noexcept(is_nothrow_invocable< const Obj &, Args &&... >::value) -> fakestd::invoke_result_t< const Obj &, Args &&... > |
Invokes the contained function object, if Obj is a callable type. More... | |
template<typename member_type > | |
enable_if_t< not std::is_member_function_pointer< member_type Obj::* >::value, member_type > & | operator->* (member_type Obj::*member) &noexcept |
Access a member variable using a pointer to member. More... | |
template<typename member_type > | |
const enable_if_t< not std::is_member_function_pointer< member_type Obj::* >::value, member_type > & | operator->* (member_type Obj::*member) const &noexcept |
Access a member variable using a pointer to member. More... | |
template<typename member_type > | |
enable_if_t< not std::is_member_function_pointer< member_type Obj::* >::value, member_type > && | operator->* (member_type Obj::*member) &&noexcept |
Access a member variable using a pointer to member. More... | |
template<typename member_type > | |
const enable_if_t< not std::is_member_function_pointer< member_type Obj::* >::value, member_type > && | operator->* (member_type Obj::*member) const &&noexcept |
Access a member variable using a pointer to member. More... | |
template<typename member_type , typename... Args> | |
auto | operator->* (member_type(Obj::*member)(Args...)) &noexcept |
Call a member function using a pointer to member. More... | |
template<typename member_type , typename... Args> | |
auto | operator->* (member_type(Obj::*member)(Args...) const) &noexcept |
Call a member function using a pointer to member. More... | |
template<typename member_type , typename... Args> | |
auto | operator->* (member_type(Obj::*member)(Args...) const) const &noexcept |
Call a member function using a pointer to member. More... | |
template<typename member_type , typename... Args> | |
auto | operator->* (member_type(Obj::*member)(Args...) const) &&noexcept |
Call a member function using a pointer to member. More... | |
template<typename member_type , typename... Args> | |
auto | operator->* (member_type(Obj::*member)(Args...) &) &noexcept |
Call a member function using a pointer to member. More... | |
template<typename member_type , typename... Args> | |
auto | operator->* (member_type(Obj::*member)(Args...) const &) &noexcept |
Call a member function using a pointer to member. More... | |
template<typename member_type , typename... Args> | |
auto | operator->* (member_type(Obj::*member)(Args...) const &) const &noexcept |
Call a member function using a pointer to member. More... | |
template<typename member_type , typename... Args> | |
auto | operator->* (member_type(Obj::*member)(Args...) &&) &&noexcept |
Call a member function using a pointer to member. More... | |
template<typename member_type , typename... Args> | |
auto | operator->* (member_type(Obj::*member)(Args...) const &) &&noexcept |
Call a member function using a pointer to member. More... | |
template<typename member_type , typename... Args> | |
auto | operator->* (member_type(Obj::*member)(Args...)) &&noexcept |
Call a member function using a pointer to member. More... | |
template<typename member_type , typename... Args> | |
auto | operator->* (member_type(Obj::*member)(Args...) const &&) &&noexcept |
Call a member function using a pointer to member. More... | |
template<typename member_type , typename... Args> | |
auto | operator->* (member_type(Obj::*member)(Args...) const &&) const &&noexcept |
Call a member function using a pointer to member. More... | |
Construction | |
constexpr | poly_obj ()=default |
The default constructor does not construct any contained object. More... | |
constexpr | poly_obj (std::nullptr_t) noexcept |
Explicitly do not construct an object. More... | |
constexpr | poly_obj (const Obj &obj) |
Copy-constructs the contained object from obj. More... | |
constexpr | poly_obj (Obj &&obj) noexcept(Traits::nothrow_movable) |
Move-constructs the contained object from obj. More... | |
template<typename... Args, typename std::enable_if_t< std::is_constructible< Obj, Args... >::value, int > = 0> | |
constexpr | poly_obj (fakestd::in_place_t, Args &&... args) noexcept(std::is_nothrow_constructible< Obj, Args &&... >::value) |
Constructs the contained object in-place without copying or moving. More... | |
template<typename... Args, typename std::enable_if_t< std::is_constructible< Obj, Args... >::value, int > = 0> | |
constexpr | poly_obj (kblib::in_place_agg_t, Args &&... args) noexcept(std::is_nothrow_constructible< Obj, Args &&... >::value) |
Constructs the contained object in-place without copying or moving. More... | |
template<typename U , typename... Args> | |
static auto | make (Args &&... args) noexcept(std::is_nothrow_constructible< U, Args &&... >::value) -> poly_obj |
Constructs a poly_obj containing an object of derived type. More... | |
template<typename U , typename... Args> | |
static auto | make_aggregate (Args &&... args) noexcept(std::is_nothrow_constructible< U, Args &&... >::value) -> poly_obj |
Constructs a poly_obj containing an object of derived type. More... | |
Copy/move operators | |
constexpr | poly_obj (const poly_obj &other) |
Constructs a copy of other. More... | |
constexpr | poly_obj (poly_obj &&other) noexcept(Traits::nothrow_movable) |
Moves the contained object of other into this. Note that the moved- from poly_obj is not cleared; instead, its contained value is moved from. More... | |
auto | operator= (const poly_obj &other) &-> poly_obj & |
Destroys the contained object, if any, and then copies other as in the copy constructor. More... | |
auto | operator= (poly_obj &&other) &noexcept(Traits::nothrow_movable) -> poly_obj & |
Destroys the contained object, if any, and then moves from other as in the move constructor. More... | |
Validity | |
Check if the poly_obj contains a value. | |
auto | has_value () const &noexcept -> bool |
operator bool () const &noexcept | |
Destruction | |
auto | clear () noexcept -> void |
Empties the poly_obj, reverting to a default-constructed state. More... | |
~poly_obj () noexcept | |
Inline polymorphic object. Generally mimics the interfaces of std::optional and std::variant.
Provides dynamic polymorphism without dynamic allocation. By default, it is copy and move constructible if and only if Obj is. The storage capacity can be overloaded in case derived objects are larger than the base (this is expected to be commonplace).
Obj | The base class type which the poly_obj will store. Must have a virtual destructor unless a custom traits class is provided. |
Capacity | The inline capacity allocated for the contained object. May be set larger than sizeof(Obj) to account for larger derived classes. A value of 0 indicates that the traits type should be used to obtain the capacity. |
Traits | A type providing member types and constants defining the allowed operations on the object type. |
Definition at line 478 of file poly_obj.h.
using kblib::poly_obj< Obj, Capacity, Traits >::base_type = Obj |
Definition at line 499 of file poly_obj.h.
using kblib::poly_obj< Obj, Capacity, Traits >::traits_type = Traits |
Definition at line 500 of file poly_obj.h.
|
constexprdefault |
The default constructor does not construct any contained object.
|
inlineconstexprnoexcept |
Explicitly do not construct an object.
Definition at line 513 of file poly_obj.h.
|
inlineconstexpr |
Copy-constructs the contained object from obj.
This function can only be called if Obj is copy-constructible.
obj | The object to copy. |
Definition at line 522 of file poly_obj.h.
|
inlineconstexprnoexcept |
Move-constructs the contained object from obj.
This function can only be called if Obj is move-constructible.
obj | The object to move from. |
Definition at line 531 of file poly_obj.h.
|
inlineexplicitconstexprnoexcept |
Constructs the contained object in-place without copying or moving.
args | Arguments to be passed to the constructor of Obj. |
Definition at line 543 of file poly_obj.h.
|
inlineexplicitconstexprnoexcept |
Constructs the contained object in-place without copying or moving.
args | Arguments to be passed to the constructor of Obj. |
Definition at line 557 of file poly_obj.h.
|
inlineconstexpr |
Constructs a copy of other.
This function can only be called if Traits::copyable is true.
other | A poly_obj to copy from. |
Definition at line 638 of file poly_obj.h.
|
inlineconstexprnoexcept |
Moves the contained object of other into this. Note that the moved- from poly_obj is not cleared; instead, its contained value is moved from.
This function can only be called if Traits::movable is true.
other | A poly_obj to move from. |
Definition at line 653 of file poly_obj.h.
|
inlinenoexcept |
Definition at line 732 of file poly_obj.h.
|
inlinenoexcept |
Empties the poly_obj, reverting to a default-constructed state.
Definition at line 724 of file poly_obj.h.
|
inlinenoexcept |
Returns a pointer to the contained object.
Returns a reference to the contained object, if it exists. If it does not exist, the behavior is undefined. Notably, the constness of *this carries over to the contained object, because it is contained inside of *this.
Definition at line 809 of file poly_obj.h.
|
inlinenoexcept |
Returns a pointer to the contained object.
Returns a reference to the contained object, if it exists. If it does not exist, the behavior is undefined. Notably, the constness of *this carries over to the contained object, because it is contained inside of *this.
Definition at line 819 of file poly_obj.h.
|
inlinenoexcept |
Definition at line 712 of file poly_obj.h.
|
inlinestaticnoexcept |
Constructs a poly_obj containing an object of derived type.
This function provides the polymorphism of poly_obj.
sizeof(U) must be less than or equal to capacity, and must be copy-constructible and move-constructible if Traits is.
U | A type publically derived from Obj. |
args | Arguments to pass to the constructor of U. |
Definition at line 575 of file poly_obj.h.
|
inlinestaticnoexcept |
Constructs a poly_obj containing an object of derived type.
This function provides the polymorphism of poly_obj.
sizeof(U) must be less than or equal to capacity, and must be copy-constructible and move-constructible if Traits is.
U | A type publically derived from Obj. |
args | Arguments to pass to the constructor of U. |
Definition at line 607 of file poly_obj.h.
|
inlineexplicitnoexcept |
Definition at line 714 of file poly_obj.h.
|
inlinenoexcept |
Invokes the contained function object, if Obj is a callable type.
Invokes the contained object, if it exists. If it does not exist, the behavior is undefined.
args | The arguments to forward to the function. |
Definition at line 871 of file poly_obj.h.
|
inlinenoexcept |
Invokes the contained function object, if Obj is a callable type.
Invokes the contained object, if it exists. If it does not exist, the behavior is undefined.
args | The arguments to forward to the function. |
Definition at line 855 of file poly_obj.h.
|
inlinenoexcept |
Returns a reference to the contained object.
Returns a reference to the contained object, if it exists. If it does not exist, the behavior is undefined. Notably, the constness and reference qualification of *this carries over to the contained object, because it is contained inside of *this.
Definition at line 778 of file poly_obj.h.
|
inlinenoexcept |
Returns a reference to the contained object.
Returns a reference to the contained object, if it exists. If it does not exist, the behavior is undefined. Notably, the constness and reference qualification of *this carries over to the contained object, because it is contained inside of *this.
Definition at line 754 of file poly_obj.h.
|
inlinenoexcept |
Returns a reference to the contained object.
Returns a reference to the contained object, if it exists. If it does not exist, the behavior is undefined. Notably, the constness and reference qualification of *this carries over to the contained object, because it is contained inside of *this.
This particular overload is not expected to be very useful, but it is provided for completeness.
Definition at line 795 of file poly_obj.h.
|
inlinenoexcept |
Returns a reference to the contained object.
Returns a reference to the contained object, if it exists. If it does not exist, the behavior is undefined. Notably, the constness and reference qualification of *this carries over to the contained object, because it is contained inside of *this.
Definition at line 765 of file poly_obj.h.
|
inlinenoexcept |
Returns a pointer to the contained object.
Returns a reference to the contained object, if it exists. If it does not exist, the behavior is undefined. Notably, the constness of *this carries over to the contained object, because it is contained inside of *this.
Definition at line 830 of file poly_obj.h.
|
inlinenoexcept |
Returns a pointer to the contained object.
Returns a reference to the contained object, if it exists. If it does not exist, the behavior is undefined. Notably, the constness of *this carries over to the contained object, because it is contained inside of *this.
Definition at line 840 of file poly_obj.h.
|
inlinenoexcept |
Access a member variable using a pointer to member.
Definition at line 904 of file poly_obj.h.
|
inlinenoexcept |
Access a member variable using a pointer to member.
Definition at line 883 of file poly_obj.h.
|
inlinenoexcept |
Access a member variable using a pointer to member.
Definition at line 915 of file poly_obj.h.
|
inlinenoexcept |
Access a member variable using a pointer to member.
Definition at line 894 of file poly_obj.h.
|
inlinenoexcept |
Call a member function using a pointer to member.
Definition at line 1008 of file poly_obj.h.
|
inlinenoexcept |
Call a member function using a pointer to member.
Definition at line 972 of file poly_obj.h.
|
inlinenoexcept |
Call a member function using a pointer to member.
Definition at line 1044 of file poly_obj.h.
|
inlinenoexcept |
Call a member function using a pointer to member.
Definition at line 1056 of file poly_obj.h.
|
inlinenoexcept |
Call a member function using a pointer to member.
Definition at line 1020 of file poly_obj.h.
|
inlinenoexcept |
Call a member function using a pointer to member.
Definition at line 984 of file poly_obj.h.
|
inlinenoexcept |
Call a member function using a pointer to member.
Definition at line 996 of file poly_obj.h.
|
inlinenoexcept |
Call a member function using a pointer to member.
Definition at line 960 of file poly_obj.h.
|
inlinenoexcept |
Call a member function using a pointer to member.
Definition at line 936 of file poly_obj.h.
|
inlinenoexcept |
Call a member function using a pointer to member.
Definition at line 948 of file poly_obj.h.
|
inlinenoexcept |
Call a member function using a pointer to member.
Definition at line 1032 of file poly_obj.h.
|
inlinenoexcept |
Call a member function using a pointer to member.
Definition at line 924 of file poly_obj.h.
|
inline |
Destroys the contained object, if any, and then copies other as in the copy constructor.
other | A poly_obj to copy from. |
@exceptions In the event that the constructor of Obj throws, the poly_obj is cleared and the exception rethrown.
Definition at line 671 of file poly_obj.h.
|
inlinenoexcept |
Destroys the contained object, if any, and then moves from other as in the move constructor.
other | A poly_obj to move from. |
@exceptions In the event that the constructor of Obj throws, the poly_obj is cleared and the exception rethrown.
Definition at line 693 of file poly_obj.h.
|
related |
A convenience factory for making poly_objs.
Definition at line 1102 of file poly_obj.h.
|
staticconstexpr |
Equal to Capacity if specified, else Traits::default_capacity.
Definition at line 491 of file poly_obj.h.