xtd 0.2.0
Loading...
Searching...
No Matches
key_value_pair.hpp
Go to the documentation of this file.
1
4#pragma once
5#include <utility>
6#include "../../is.hpp"
7#include "../../object.hpp"
8#include "../../iequatable.hpp"
9#include "../../static.hpp"
10#define __XTD_CORE_INTERNAL__
11#include "../../internal/__key_value_pair_definition.hpp"
12#undef __XTD_CORE_INTERNAL__
13
15namespace xtd {
17 namespace collections {
19 namespace generic {
35 template <typename key_t, typename value_t>
36 class key_value_pair : public xtd::object, public xtd::iequatable<key_value_pair<key_t, value_t>> {
37 public:
39
42 using base_type = std::pair<key_t, value_t>;
44 using key_type = key_t;
46 using value_type = value_t;
52
54
57 key_value_pair() = default;
61 key_value_pair(const key_t& key, const value_t& value) : first {key}, second {value} {}
64 key_value_pair(const std::pair<key_t, value_t>& value) : first {value.first}, second {value.second} {} // Can't be explicit by design.
66
68
71 key_t first = key_t {};
73 value_t second = value_t {};
74
77 const key_t& key() const noexcept {
78 return first;
79 };
80
83 const value_t& value() const noexcept {
84 return second;
85 };
87
89
94 xtd::string to_string() const noexcept override;
95
99 bool equals(const key_value_pair& value) const noexcept override {return first == value.first && second == value.second;}
100
104 bool equals(const object& obj) const noexcept override {return is<key_value_pair>(obj) && equals(static_cast<const key_value_pair&>(obj));}
106
108
112 operator std::pair<key_t, value_t>() const noexcept {return {first, second};}
114 };
115
131 template <>
133 public:
135
143 template<typename key_t, typename value_t>
146 };
147 }
148 }
149}
Represents text as a sequence of character units.
Definition basic_string.hpp:79
static key_value_pair< key_t, value_t > create(key_t key, value_t value)
Creates a key_value_pair from specified key and value.
Definition key_value_pair.hpp:144
Defines a key/value pair that can be set or retrieved.
Definition key_value_pair.hpp:36
key_value_pair()=default
Initializes a new instance of the key_value_pair<key_t, value_t> class with the default key and value...
bool equals(const key_value_pair &value) const noexcept override
Determines whether the specified object is equal to the current object.
Definition key_value_pair.hpp:99
value_t value_type
Representd the type of the value.
Definition key_value_pair.hpp:46
key_value_pair(const key_t &key, const value_t &value)
Initializes a new instance of the key_value_pair<key_t, value_t> class with the specified key and val...
Definition key_value_pair.hpp:61
bool equals(const object &obj) const noexcept override
Determines whether the specified object is equal to the current object.
Definition key_value_pair.hpp:104
value_t second
Gets or sets the value in the key/value pair.
Definition key_value_pair.hpp:73
key_value_pair(const std::pair< key_t, value_t > &value)
Initializes a new instance of the key_value_pair<key_t, value_t> class with the specified key and val...
Definition key_value_pair.hpp:64
key_t key_type
Represents the type of the key.
Definition key_value_pair.hpp:44
const key_t & key() const noexcept
Gets the key in the key/value pair.
Definition key_value_pair.hpp:77
key_t first
Gets or sets the key in the key/value pair.
Definition key_value_pair.hpp:71
xtd::string to_string() const noexcept override
Returns a String representation of the key_value_pair<key_t, value_t>, using the String representatio...
key_type first_type
Represents the type of the first.
Definition key_value_pair.hpp:48
const value_t & value() const noexcept
Gets the value in the key/value pair.
Definition key_value_pair.hpp:83
value_type second_type
Represents the type of the second.
Definition key_value_pair.hpp:50
std::pair< key_t, value_t > base_type
Represents the type of the base.
Definition key_value_pair.hpp:42
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.hpp:22
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:42
#define static_
This keyword is use to represent a static object. A static object can't be instantiated (constructors...
Definition static.hpp:37
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10