xtd 0.2.0
Loading...
Searching...
No Matches
xtd::box< type_t > Struct Template Reference
Inheritance diagram for xtd::box< type_t >:
xtd::object xtd::icomparable< box< type_t > > xtd::iequatable< box< type_t > > xtd::iformatable xtd::interface xtd::extensions::comparison_operators< type_t, icomparable< type_t > > xtd::interface xtd::extensions::equality_operators< type_t, iequatable< type_t > > xtd::interface xtd::box_integer< xtd::byte > xtd::box_integer< int16 > xtd::box_integer< int32 > xtd::box_integer< int64 > xtd::box_integer< intptr > xtd::box_integer< ptrdiff > xtd::box_integer< sbyte > xtd::box_integer< size_t > xtd::box_integer< slong > xtd::box_integer< uint16 > xtd::box_integer< uint32 > xtd::box_integer< uint64 > xtd::box_integer< uintptr > xtd::box_integer< ulong > xtd::box_integer< type_t >

Definition

template<typename type_t>
struct xtd::box< type_t >

Represents a boxed object.

template<typename type_t>
struct box : xtd::object, xtd::icomparable<box<type_t>>, xtd::iequatable<box<type_t>>, xtd::iformatable;
Defines a generalized comparison method that a value type or class implements to create a type-specif...
Definition icomparable.hpp:22
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.hpp:23
Provides functionality to format the value of an object into a string representation.
Definition iformatable.hpp:42
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:45
box()=default
Initialize a new xtd::box object.
Inheritance
xtd::objectxtd::box <type_t>
Implements
xtd::icomparable <>, xtd::iequatable <>
Header
#include <xtd/box>
Namespace
xtd
Library
xtd.core
Remarks
You can use xtd::box to represent a class or structure that does not inherit from xtd::object. Typically used for integral types.
Use xtd::boxing to box an object.
Use xtd::unboxing to unbox an object.
The boxed object must implement operator == and operator < because a xtd::box implement xtd::icomparable and xtd::iequatable interfaces.
For more information about types, see Native types, boxing and unboxing.
Examples
The following example shows how to create and use xtd::box<bool>.
auto stringer = [](const object& value) {return value.to_string();};
bool unboxed_object = true;
box<bool> boxed_object = unboxed_bool;
auto result = stringer(boxed_object);
console::write_line("result = {}", result); // Display: result = true;
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
Represents a boxed object.
Definition box.hpp:56
value_type value
Gets or sets the underlying value.
Definition box.hpp:106

Public Aliases

using value_type
 Represents the value type.
using reference
 Represents the reference type.
using const_reference
 Represents the cont reference type.
using pointer
 Represents the reference type.
using const_pointer
 Represents the cont reference type.

Public Properties

value_type value
 Gets or sets the underlying value.

Public Constructors

 box ()=default
 Initialize a new xtd::box object.
 box (const_reference value)
 Initialize a new xtd::box object with specified value.
template<typename ... args_t>
 box (args_t &&...args)
 Initialize a new xtd::box object with specified value.

Public Opertors

 operator value_type () const noexcept
 Cast operator to the value type.

Public Methods

auto compare_to (const box &value) const noexcept -> xtd::int32 override
 Compares the current instance with another object of the same type.
auto equals (const object &obj) const noexcept -> bool override
 Determines whether the specified object is equal to the current object.
auto equals (const box &value) const noexcept -> bool override
 Indicates whether the current object is equal to another object of the same type.
auto get_hash_code () const noexcept -> xtd::size override
 Serves as a hash function for a particular type.
auto to_string () const noexcept -> xtd::string override
 Returns a xtd::string that represents the current object.
auto to_string (const xtd::string &format) const -> xtd::string
 Converts the value of this instance to its equivalent string representation, using the specified format.
auto to_string (const xtd::string &format, const globalization::culture_info &culture) const -> xtd::string override
 Converts the value of this instance to its equivalent string representation, using the specified format, and locale.

Public Static Methods

static auto parse (const xtd::string &value) -> value_type
 Converts the string to its value_type equivalent.
static auto try_parse (const xtd::string &value, reference result) noexcept -> bool
 Converts the string to its value_type equivalent. A return value indicates whether the conversion succeeded or failed.

Additional Inherited Members

 object ()=default
 Create a new instance of the ultimate base class object.
virtual type_object get_type () const noexcept
 Gets the type of the current instance.
template<typename object_t>
xtd::unique_ptr_object< object_t > memberwise_clone () const
 Creates a shallow copy of the current object.
virtual int32 compare_to (const type_t &obj) const noexcept=0
 Compares the current instance with another object of the same type.
virtual bool equals (const type_t &) const noexcept=0
 Indicates whether the current object is equal to another object of the same type.
template<typename object_a_t, typename object_b_t>
static bool equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are considered equal.
template<typename object_a_t, typename object_b_t>
static bool reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are the same instance.

Member Typedef Documentation

◆ value_type

template<typename type_t>
using xtd::box< type_t >::value_type

Represents the value type.

◆ reference

template<typename type_t>
using xtd::box< type_t >::reference

Represents the reference type.

◆ const_reference

template<typename type_t>
using xtd::box< type_t >::const_reference

Represents the cont reference type.

◆ pointer

template<typename type_t>
using xtd::box< type_t >::pointer

Represents the reference type.

◆ const_pointer

template<typename type_t>
using xtd::box< type_t >::const_pointer

Represents the cont reference type.

Constructor & Destructor Documentation

◆ box() [1/3]

template<typename type_t>
xtd::box< type_t >::box ( )
default

Initialize a new xtd::box object.

◆ box() [2/3]

template<typename type_t>
xtd::box< type_t >::box ( const_reference value)
inline

Initialize a new xtd::box object with specified value.

Parameters
valueValue used to initialize object.

◆ box() [3/3]

template<typename type_t>
template<typename ... args_t>
xtd::box< type_t >::box ( args_t &&... args)
inline

Initialize a new xtd::box object with specified value.

Parameters
...args_tParams used to initialize object.

Member Function Documentation

◆ operator value_type()

template<typename type_t>
xtd::box< type_t >::operator value_type ( ) const
inlinenoexcept

Cast operator to the value type.

Returns
The xtd::box current instnce to value_type.

◆ compare_to()

template<typename type_t>
auto xtd::box< type_t >::compare_to ( const box< type_t > & value) const -> xtd::int32
inlinenodiscardoverridenoexcept

Compares the current instance with another object of the same type.

Parameters
valueAn object to compare with this instance.
Returns
A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has these meanings:
Value Condition
Less than zero This instance is less than obj.
Zero This instance is equal to obj.
Greater than zero This instance is greater than obj.

◆ equals() [1/2]

template<typename type_t>
auto xtd::box< type_t >::equals ( const object & obj) const -> bool
inlinenodiscardoverridevirtualnoexcept

Determines whether the specified object is equal to the current object.

Parameters
objThe object to compare with the current object.
Returns
true if the specified object is equal to the current object. otherwise, false.

Reimplemented from xtd::object.

◆ equals() [2/2]

template<typename type_t>
auto xtd::box< type_t >::equals ( const box< type_t > & value) const -> bool
inlinenodiscardoverridenoexcept

Indicates whether the current object is equal to another object of the same type.

Parameters
objAn object to compare with this object.
Returns
true if the current object is equal to the other parameter; otherwise, false.

◆ get_hash_code()

template<typename type_t>
auto xtd::box< type_t >::get_hash_code ( ) const -> xtd::size
inlinenodiscardoverridevirtualnoexcept

Serves as a hash function for a particular type.

Returns
size_t A hash code for the current object.

Reimplemented from xtd::object.

◆ to_string() [1/3]

template<typename type_t>
auto xtd::box< type_t >::to_string ( ) const -> xtd::string
nodiscardoverridevirtualnoexcept

Returns a xtd::string that represents the current object.

Returns
A string that represents the current object.

Reimplemented from xtd::object.

Examples
application_restart.cpp, and console_out.cpp.

◆ to_string() [2/3]

template<typename type_t>
auto xtd::box< type_t >::to_string ( const xtd::string & format) const -> xtd::string
nodiscard

Converts the value of this instance to its equivalent string representation, using the specified format.

Parameters
formatA value type format string.
Returns
The string representation of the value of this instance as specified by format.

◆ to_string() [3/3]

template<typename type_t>
auto xtd::box< type_t >::to_string ( const xtd::string & format,
const globalization::culture_info & culture ) const -> xtd::string
nodiscardoverridevirtual

Converts the value of this instance to its equivalent string representation, using the specified format, and locale.

Parameters
formatA value type format string.
cultureAn xtd::globalization::culture_info object that contains culture information.
Returns
The string representation of the value of this instance as specified by format.

Implements xtd::iformatable.

◆ parse()

template<typename type_t>
auto xtd::box< type_t >::parse ( const xtd::string & value) -> value_type
inlinestaticnodiscard

Converts the string to its value_type equivalent.

Parameters
valueA string containing a value_type to convert.
Returns
A value_type equivalent to the native value contained in value.

◆ try_parse()

template<typename type_t>
auto xtd::box< type_t >::try_parse ( const xtd::string & value,
reference result ) -> bool
inlinestaticnoexcept

Converts the string to its value_type equivalent. A return value indicates whether the conversion succeeded or failed.

Parameters
valueA string containing a value_type to convert.
resultA value_type equivalent to the native value contained in value.
Returns
true if s was converted successfully; otherwise, false.

Member Data Documentation

◆ value

template<typename type_t>
value_type xtd::box< type_t >::value

Gets or sets the underlying value.

Parameters
valueThe value to set to the underlying value.

The documentation for this struct was generated from the following file: