Skip to content

Commit 15f0a84

Browse files
committed
remove xtd::optional for operator 'controls()[name]'
1 parent edabcaa commit 15f0a84

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

examples/xtd.forms.examples/others/control_with_name_operator/src/control_with_name_operator.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ namespace control_with_name_operator_example {
88
button1.name("button1");
99
label1.name("label1");
1010

11-
controls()["button1"].value().get().location({10, 10});
12-
controls()["button1"].value().get().text("Click me");
13-
as<button>(controls()["button1"].value().get()).auto_repeat(true);
14-
controls()["button1"].value().get().click += delegate_ {
11+
controls()["button1"].get().location({10, 10});
12+
controls()["button1"].get().text("Click me");
13+
as<button>(controls()["button1"].get()).auto_repeat(true);
14+
controls()["button1"].get().click += delegate_ {
1515
static int count = 0;
16-
controls()["label1"].value().get().text(string::format("button clicked {} times", ++count));
16+
controls()["label1"].get().text(string::format("button clicked {} times", ++count));
1717
};
1818

19-
controls()["label1"].value().get().auto_size(true);
20-
controls()["label1"].value().get().location({10, 50});
21-
controls()["label1"].value().get().text("button clicked 0 times");
19+
controls()["label1"].get().auto_size(true);
20+
controls()["label1"].get().location({10, 50});
21+
controls()["label1"].get().text("button clicked 0 times");
2222
}
2323

2424
private:

examples/xtd.forms.examples/others/emplace/src/emplace.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ auto main() -> int {
44
auto button1_clicked = 0, button2_clicked = 0;
55
auto form1 = form::create("Emplace example");
66
form1.controls().emplace_front<button>("Button 1", point{50, 50}).click += delegate_ {
7-
form1.controls()["label1"].value().get().text(string::format("Button 1 clicked {} times", ++button1_clicked));
7+
form1.controls()["label1"].get().text(string::format("Button 1 clicked {} times", ++button1_clicked));
88
};
99
form1.controls().emplace_at<button>(1, "Button 2", point {50, 100}, drawing::size {200, 75}).auto_repeat(true).click += delegate_ {
10-
form1.controls()["label2"].value().get().text(string::format("Button 2 clicked {} times", ++button2_clicked));
10+
form1.controls()["label2"].get().text(string::format("Button 2 clicked {} times", ++button2_clicked));
1111
};
1212
form1.controls().emplace_at<label>(2, "Button 1 clicked 0 times", point {50, 200}, drawing::size {200, 23}, "label1");
1313
form1.controls().emplace_back<label>("Button 2 clicked 0 times", point {50, 230}, drawing::size {200, 23}, "label2");

src/xtd.forms/include/xtd/forms/control.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,12 @@ namespace xtd {
186186
/// @param name The name of the xtd::forms::control to get from the list.
187187
/// @return The first xtd::forms::control in the list with the given Name. This item returns optional with no value if no xtd::forms::control with the given name can be found.
188188
/// @remarks The operator [] property is case-sensitive when searching for names. That is, if two controls exist with the names "Lname" and "lname", operator [] property will find only the xtd::forms::control with the xtd::forms::control::name() that you specify, not both.
189-
std::optional<value_type> operator [](const xtd::string& name) const;
189+
value_type operator [](const xtd::string& name) const;
190190
/// @brief Gets the first xtd::forms::control::control_collection in the list with the specified name.
191191
/// @param name The name of the xtd::forms::control to get from the list.
192192
/// @return The first xtd::forms::control in the list with the given Name. This item returns optional with no value if no xtd::forms::control with the given name can be found.
193193
/// @remarks The operator [] property is case-sensitive when searching for names. That is, if two controls exist with the names "Lname" and "lname", operator [] property will find only the xtd::forms::control with the xtd::forms::control::name() that you specify, not both.
194-
std::optional<value_type> operator [](const xtd::string& name);
194+
value_type operator [](const xtd::string& name);
195195
/// @}
196196

197197
/// @name Public Methods

src/xtd.forms/src/xtd/forms/control.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ control::control_collection& control::control_collection::operator = (const cont
105105
return *this;
106106
}
107107

108-
std::optional<control::control_collection::value_type> control::control_collection::operator [](const string& name) const {
108+
control::control_collection::value_type control::control_collection::operator [](const string& name) const {
109109
for (auto item : *this)
110110
if (item.get().name() == name) return item;
111111
return {};
112112
}
113113

114-
std::optional<control::control_collection::value_type> control::control_collection::operator [](const string& name) {
114+
control::control_collection::value_type control::control_collection::operator [](const string& name) {
115115
for (auto item : *this)
116116
if (item.get().name() == name) return item;
117117
return std::nullopt;

0 commit comments

Comments
 (0)