xtd 0.2.0
Loading...
Searching...
No Matches
xtd::collections::generic::params< type_t > Class Template Referencefinal
Inheritance diagram for xtd::collections::generic::params< type_t >:
xtd::object

Definition

template<typename type_t>
class xtd::collections::generic::params< type_t >

An object of type xtd::collections::generic::params <type_t> is a lightweight proxy object that provides access to an array of objects of type const type_t (that may be allocated in read-only memory).

template<typename type_t>
class params : public xtd::object
An object of type xtd::collections::generic::params <type_t> is a lightweight proxy object that provi...
Definition params.h:40
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:42
Header
#include <xtd/collections/generic/params
Namespace
xtd::collections::generic
Library
xtd.core
Remarks
This class cannot be inherited.
A xtd::collections::generic::params object is automatically constructed when:
xtd::collections::generic::params may be implemented as a pair of pointers or pointer and length. Copying a xtd::collections::generic::params does not copy the backing array of the corresponding params.
xtd::collections::generic::params is exactly The same as std::initializer_list object.
Warning
When creating your own container, use the std::initializer_list object instead of the xtd::collections::generic::params object for the constructor, because C++ compilers use a magic trick (such as a private constructor) to initialize elements correctly. Use xtd::collections::generic::params when initializing elements yourself.
Examples
The following example demonstrates how to usea xtd::collections::generic::params <type_t> class.
#include <xtd/collections/generic/list>
#include <xtd/console>
#include <xtd/startup>
#include <xtd/time_span>
#include <vector>
using namespace xtd;
using namespace xtd::collections::generic;
class program {
public:
static auto main() -> void {
console::write_line("params = {}", params {1, 2, 3, 4, 5});
console::write_line("list = {}", list<int> {params {1, 2, 3, 4, 5}});
console::write_line("vector = {}", std::vector<int> {params {1, 2, 3, 4, 5}});
console::write_line("create_list = {}", create_list(params {"one", "two", "three", "four", "five"}));
console::write_line("create_vector = {}", create_vector(params {3_h + 2_min + 1_s, 3_h + 2_min + 2_s, 3_h + 2_min + 3_s, 3_h + 2_min + 4_s, 3_h + 2_min + 5_s}));
}
private:
template <typename type_t>
static list<type_t> create_list(params<type_t> items) {
return list<type_t> {items};
}
template <typename type_t>
static std::vector<type_t> create_vector(params<type_t> items) {
return std::vector<type_t> {items};
}
};
startup_(program::main);
// This code can produce the following output :
//
// params = [1, 2, 3, 4, 5]
// list = [1, 2, 3, 4, 5]
// vector = [1, 2, 3, 4, 5]
// create_list = [1, 2, 3, 4, 5]
// create_vector = [03:02:01, 03:02:02, 03:02:03, 03:02:04, 03:02:05]
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition list.h:72
#define startup_(main_method)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.h:175
The xtd::collections::generic namespace contains interfaces and classes that define generic collectio...
Definition comparer.h:15
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10

Public Alias

using base_type = std::initializer_list< type_t >
 Represents the params base type.
 
using value_type = typename base_type::value_type
 Represents the params value type.
 
using reference = typename base_type::reference
 Represents the reference of params value type.
 
using const_reference = typename base_type::const_reference
 Represents the const reference of params value type.
 
using const_pointer = const value_type *
 Represents the const pointer of params value type.
 
using size_type = typename base_type::size_type
 Represents the params size type (usually xtd::size).
 
using iterator = typename base_type::iterator
 Represents the iterator of params value type.
 
using const_iterator = typename base_type::const_iterator
 Represents the const iterator of params value type.
 

Public Constructors

constexpr params () noexcept=default
 Create a new instance of the class xtd::collections::generic::params.
 

Public Properties

constexpr iterator begin () const noexcept
 Returns a pointer to the first element in the params.
 
virtual const_pointer data () const noexcept
 Returns pointer to the underlying array serving as element storage.
 
constexpr iterator end () const noexcept
 Returns a pointer to one past the last element in the params, i.e. begin() + size().
 
virtual const base_typeitems () const noexcept
 Returns the underlying base type items.
 
constexpr size_type size () const noexcept
 Returns the number of elements in the params, i.e. std::distance(begin(), end()).
 

Public Methods

xtd::string to_string () const noexcept override
 Returns a xtd::string that represents the current object.
 

Public Operators

 operator const base_type & () const noexcept
 Returns a reference to the underlying base type.
 
 operator base_type & () noexcept
 Returns a reference to the underlying base type.
 

Additional Inherited Members

- Public Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object.
 
virtual bool equals (const object &obj) const noexcept
 Determines whether the specified object is equal to the current object.
 
virtual size_t get_hash_code () const noexcept
 Serves as a hash function for a particular type.
 
virtual type_object get_type () const noexcept
 Gets the type of the current instance.
 
template<typename object_t >
xtd::uptr< object_t > memberwise_clone () const
 Creates a shallow copy of the current object.
 
- Static Public Member Functions inherited from xtd::object
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

◆ base_type

template<typename type_t >
using xtd::collections::generic::params< type_t >::base_type = std::initializer_list<type_t>

Represents the params base type.

◆ value_type

template<typename type_t >
using xtd::collections::generic::params< type_t >::value_type = typename base_type::value_type

Represents the params value type.

◆ reference

template<typename type_t >
using xtd::collections::generic::params< type_t >::reference = typename base_type::reference

Represents the reference of params value type.

◆ const_reference

template<typename type_t >
using xtd::collections::generic::params< type_t >::const_reference = typename base_type::const_reference

Represents the const reference of params value type.

◆ const_pointer

template<typename type_t >
using xtd::collections::generic::params< type_t >::const_pointer = const value_type*

Represents the const pointer of params value type.

◆ size_type

template<typename type_t >
using xtd::collections::generic::params< type_t >::size_type = typename base_type::size_type

Represents the params size type (usually xtd::size).

◆ iterator

template<typename type_t >
using xtd::collections::generic::params< type_t >::iterator = typename base_type::iterator

Represents the iterator of params value type.

◆ const_iterator

template<typename type_t >
using xtd::collections::generic::params< type_t >::const_iterator = typename base_type::const_iterator

Represents the const iterator of params value type.

Constructor & Destructor Documentation

◆ params()

template<typename type_t >
constexpr xtd::collections::generic::params< type_t >::params ( )
constexprdefaultnoexcept

Create a new instance of the class xtd::collections::generic::params.

Member Function Documentation

◆ begin()

template<typename type_t >
constexpr iterator xtd::collections::generic::params< type_t >::begin ( ) const
inlineconstexprnoexcept

Returns a pointer to the first element in the params.

Returns
A pointer to the first element in the params.
Remarks
If the params is empty, the values of begin() and end() are unspecified, but will be identical.

◆ data()

template<typename type_t >
virtual const_pointer xtd::collections::generic::params< type_t >::data ( ) const
inlinevirtualnoexcept

Returns pointer to the underlying array serving as element storage.

Returns
Pointer to the underlying element storage. For non-empty containers, the returned pointer compares equal to the address of the first element.
Remarks
The pointer is such that range [xtd::collections::generic::list::data(), xtd::collections::generic::list::data() + xtd::collections::generic::list::size()) is always a valid range, even if the container is empty (xtd::collections::generic::list::data() is not dereferenceable in that case).

◆ end()

template<typename type_t >
constexpr iterator xtd::collections::generic::params< type_t >::end ( ) const
inlineconstexprnoexcept

Returns a pointer to one past the last element in the params, i.e. begin() + size().

Returns
A pointer to one past the last element in the params.
Remarks
If the params is empty, the values of begin() and end() are unspecified, but will be identical.

◆ items()

template<typename type_t >
virtual const base_type & xtd::collections::generic::params< type_t >::items ( ) const
inlinevirtualnoexcept

Returns the underlying base type items.

Returns
The underlying base type items.

◆ size()

template<typename type_t >
constexpr size_type xtd::collections::generic::params< type_t >::size ( ) const
inlineconstexprnoexcept

Returns the number of elements in the params, i.e. std::distance(begin(), end()).

Returns
The number of elements in the params.

◆ to_string()

template<typename type_t >
xtd::string xtd::collections::generic::params< type_t >::to_string ( ) const
inlineoverridevirtualnoexcept

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

Returns
A string that represents the current object.
Examples
The following code example demonstrates what to_string returns.
#include <xtd/xtd>
using namespace xtd;
namespace examples {
namespace object_test {
class object1 : public object {
};
}
}
auto main() -> int {
ptr<object> obj1 = new_ptr<examples::object_test::object1>();
console::write_line(obj1->to_string());
ptr<object> obj2 = new_ptr<date_time>(1971, 1, 5, 23, 5, 0);
console::write_line(obj2->to_string());
ptr<object> obj3 = new_ptr<boolean_object>();
console::write_line(obj3->to_string());
}
// This code produces the following output :
//
// examples::object_test::object1
// Tue Jan 5 23:05:00 1971
// false
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
xtd::sptr< type_t > ptr
The xtd::ptr object is a shared pointer.
Definition ptr.h:27

Reimplemented from xtd::object.

◆ operator const base_type &()

template<typename type_t >
xtd::collections::generic::params< type_t >::operator const base_type & ( ) const
inlinenoexcept

Returns a reference to the underlying base type.

Returns
Reference to the underlying base type.

◆ operator base_type &()

template<typename type_t >
xtd::collections::generic::params< type_t >::operator base_type & ( )
inlinenoexcept

Returns a reference to the underlying base type.

Returns
Reference to the underlying base type.

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