xtd 0.2.0
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, comparable_t > xtd::interface xtd::extensions::equality_operators< type_t, equatable_t > xtd::interface xtd::box_integer< type_t > xtd::box_char< type_t > xtd::box_floating_point< type_t >

Definition

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

Represents a boxed object.

template<class 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:21
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.hpp:22
Provides functionality to format the value of an object into a string representation.
Definition iformatable.hpp:35
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:43
Represents a boxed object.
Definition box.hpp:57
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...
value_type value
Gets or sets the underlying value.
Definition box.hpp:107
Examples
generic_icollection.cpp, generic_ienumerable2.cpp, generic_ienumerator.cpp, and generic_ilist.cpp.

Public Aliases

using value_type = type_t
 
using reference = type_t &
 Represents the reference type.
 
using const_reference = const type_t &
 Represents the cont reference type.
 
using pointer = type_t *
 Represents the reference type.
 
using const_pointer = const type_t *
 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<class ... 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

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

Public Static Methods

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

Additional Inherited Members

- Public Member Functions inherited from xtd::object
 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<class object_t >
xtd::uptr< object_t > memberwise_clone () const
 Creates a shallow copy of the current object.
 
- Public Member Functions inherited from xtd::icomparable< box< type_t > >
- Public Member Functions inherited from xtd::iequatable< box< type_t > >
- Public Member Functions inherited from xtd::iformatable
- Static Public Member Functions inherited from xtd::object
template<class object_a_t , class 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<class object_a_t , class 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<class type_t >
using xtd::box< type_t >::value_type = type_t

Represents the value type.

◆ reference

template<class type_t >
using xtd::box< type_t >::reference = type_t&

Represents the reference type.

◆ const_reference

template<class type_t >
using xtd::box< type_t >::const_reference = const type_t&

Represents the cont reference type.

◆ pointer

template<class type_t >
using xtd::box< type_t >::pointer = type_t*

Represents the reference type.

◆ const_pointer

template<class type_t >
using xtd::box< type_t >::const_pointer = const type_t*

Represents the cont reference type.

Constructor & Destructor Documentation

◆ box() [1/3]

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

Initialize a new xtd::box object.

◆ box() [2/3]

template<class 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<class type_t >
template<class ... 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<class 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<class type_t >
int32 xtd::box< type_t >::compare_to ( const box< type_t > &  value) const
inlineoverridevirtualnoexcept

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.

Implements xtd::icomparable< box< type_t > >.

◆ equals() [1/2]

template<class type_t >
bool xtd::box< type_t >::equals ( const object obj) const
inlineoverridevirtualnoexcept

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<class type_t >
bool xtd::box< type_t >::equals ( const box< type_t > &  value) const
inlineoverridevirtualnoexcept

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.

Implements xtd::iequatable< box< type_t > >.

◆ get_hash_code()

template<class type_t >
xtd::size xtd::box< type_t >::get_hash_code ( ) const
inlineoverridevirtualnoexcept

Serves as a hash function for a particular type.

Returns
size_t A hash code for the current object.

Reimplemented from xtd::object.

Examples
generic_icollection.cpp.

◆ to_string() [1/3]

template<class type_t >
xtd::string xtd::box< type_t >::to_string ( ) const
inlineoverridevirtualnoexcept

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, console_out.cpp, and generic_ienumerable2.cpp.

◆ to_string() [2/3]

template<class type_t >
xtd::string xtd::box< type_t >::to_string ( const xtd::string format) const
inline

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<class type_t >
xtd::string xtd::box< type_t >::to_string ( const xtd::string format,
const std::locale &  loc 
) const
inlineoverridevirtual

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

Parameters
formatA value type format string.
locAn std::locale object that contains locale information (see std::locale).
Returns
The string representation of the value of this instance as specified by format.

Implements xtd::iformatable.

◆ parse()

template<class type_t >
static value_type xtd::box< type_t >::parse ( const xtd::string value)
inlinestatic

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<class type_t >
static bool xtd::box< type_t >::try_parse ( const xtd::string value,
reference  result 
)
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<class 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: