-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support binding std::optional<T> implementation to IReference<T> para…
…meters (#1030)
- Loading branch information
Showing
7 changed files
with
78 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include "pch.h" | ||
#include "winrt/test_component.h" | ||
|
||
using namespace winrt; | ||
|
||
TEST_CASE("optional") | ||
{ | ||
test_component::Optional object; | ||
|
||
object.Property(Windows::Foundation::IReference(123)); | ||
REQUIRE(object.Property().Value() == 123); | ||
|
||
object.Property(nullptr); | ||
REQUIRE(object.Property() == nullptr); | ||
|
||
object.Property(456); | ||
REQUIRE(object.Property().Value() == 456); | ||
|
||
object.Property(std::optional(789)); | ||
std::optional<int32_t> value = object.Property(); | ||
REQUIRE(value == std::optional(789)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#include "pch.h" | ||
#include "Optional.h" | ||
#include "Optional.g.cpp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#pragma once | ||
#include "Optional.g.h" | ||
|
||
namespace winrt::test_component::implementation | ||
{ | ||
struct Optional : OptionalT<Optional> | ||
{ | ||
Optional() = default; | ||
|
||
Windows::Foundation::IReference<int32_t> Property() | ||
{ | ||
return m_property; | ||
} | ||
|
||
void Property(Windows::Foundation::IReference<int32_t> const& value) | ||
{ | ||
m_property = value; | ||
} | ||
|
||
std::optional<int32_t> m_property; | ||
}; | ||
} | ||
namespace winrt::test_component::factory_implementation | ||
{ | ||
struct Optional : OptionalT<Optional, implementation::Optional> | ||
{ | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters