xtd 0.2.0
key_value_pair.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "../../is.hpp"
6#include "../../object.hpp"
7#include "../../iequatable.hpp"
8#include "../../static.hpp"
9#define __XTD_CORE_INTERNAL__
10#include "../../internal/__key_value_pair_definition.hpp"
11#undef __XTD_CORE_INTERNAL__
12#include <utility>
13#include <tuple>
14
16namespace xtd {
18 namespace collections {
20 namespace generic {
36 template <class key_t, class value_t>
37 struct key_value_pair : xtd::object, xtd::iequatable<key_value_pair<key_t, value_t>> {
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} {}
65 template <class key_type_t, class value_type_t>
66 key_value_pair(key_type_t&& key, value_type_t&& value) : first(std::move(key)), second(std::move(value)) {}
69 key_value_pair(const std::pair<key_t, value_t>& value) : first {value.first}, second {value.second} {} // Can't be explicit by design.
72 key_value_pair(std::pair<key_t, value_t>&& value) : first {std::move(value.first)}, second {std::move(value.second)} {}
76 template<class... args1_t, class... args2_t>
77 key_value_pair(std::piecewise_construct_t, std::tuple<args1_t...> first_args, std::tuple<args2_t...> second_args) : first {first_args}, second {second_args} {}
79
81 key_value_pair(key_value_pair&&) = default;
82 key_value_pair(const key_value_pair&) = default;
83 key_value_pair& operator =(key_value_pair&&) = default;
84 key_value_pair& operator =(const key_value_pair&) = default;
86
88
91 key_t first = key_t {};
93 value_t second = value_t {};
94
97 const key_t& key() const noexcept {return first;}
98
101 const value_t& value() const noexcept {return second;}
103
105
110 bool equals(const object& obj) const noexcept override {return is<key_value_pair>(obj) && equals(static_cast<const key_value_pair&>(obj));}
111
115 bool equals(const key_value_pair& value) const noexcept override {return first == value.first && second == value.second;}
116
120 xtd::string to_string() const noexcept override; // defined in "../../string.hpp"
122
124
128 operator std::pair<key_t, value_t>() const noexcept {return {first, second};}
130 };
131
147 template <>
150
158 template<class key_t, class value_t>
161 };
162
164 // C++17 deduction guides for xtd::collections::generic::key_value_pair
165 // {
166 template<class key_t, class value_t>
167 key_value_pair(key_t, value_t) -> key_value_pair<key_t, value_t>;
168 // }
170 }
171 }
172}
Represents text as a sequence of character units.
Definition basic_string.hpp:71
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:43
#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
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:159
Defines a key/value pair that can be set or retrieved.
Definition key_value_pair.hpp:37
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:115
key_value_pair(std::piecewise_construct_t, std::tuple< args1_t... > first_args, std::tuple< args2_t... > second_args)
Initializes a new instance of the key_value_pair<key_t, value_t> class with the specified first_args ...
Definition key_value_pair.hpp:77
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:110
value_t second
Gets or sets the value in the key/value pair.
Definition key_value_pair.hpp:93
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:69
key_t key_type
Represents the type of the key.
Definition key_value_pair.hpp:44
key_value_pair(key_type_t &&key, value_type_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:66
const key_t & key() const noexcept
Gets the key in the key/value pair.
Definition key_value_pair.hpp:97
key_t first
Gets or sets the key in the key/value pair.
Definition key_value_pair.hpp:91
key_value_pair(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:72
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:101
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