Nullable::Emplace() to set HasValue() (#5178)
Co-authored-by: Anton Kolesnyk <antkmsft@users.noreply.github.com>
This commit is contained in:
Родитель
ee4be19b3f
Коммит
fbf58139f7
|
@ -8,6 +8,7 @@
|
|||
|
||||
### Bugs Fixed
|
||||
|
||||
- [[#5172]](https://github.com/Azure/azure-sdk-for-cpp/issues/5172) `Azure::Nullable::Emplace()` does not set `HasValue()` to `true`.
|
||||
- [[#5130]](https://github.com/Azure/azure-sdk-for-cpp/issues/5130) `Url::AppendPath()` and `Url::SetPath()` may end up with a double slash at the beginning of a path.
|
||||
|
||||
### Other Changes
|
||||
|
|
|
@ -218,6 +218,7 @@ public:
|
|||
{
|
||||
Reset();
|
||||
::new (static_cast<void*>(&m_value)) T(std::forward<U>(Args)...);
|
||||
m_hasValue = true;
|
||||
return m_value;
|
||||
}
|
||||
|
||||
|
|
|
@ -99,6 +99,34 @@ TEST(Nullable, ValueAssignment)
|
|||
EXPECT_FALSE(strVal.HasValue());
|
||||
}
|
||||
|
||||
TEST(Nullable, Emplace)
|
||||
{
|
||||
{
|
||||
Azure::Nullable<int> x;
|
||||
EXPECT_FALSE(x.HasValue());
|
||||
EXPECT_EQ(x.Emplace(42), 42);
|
||||
EXPECT_TRUE(x.HasValue());
|
||||
EXPECT_EQ(x.Value(), 42);
|
||||
}
|
||||
|
||||
{
|
||||
Azure::Nullable<int> y;
|
||||
EXPECT_FALSE(y.HasValue());
|
||||
EXPECT_EQ(y.Emplace(), 0);
|
||||
EXPECT_TRUE(y.HasValue());
|
||||
EXPECT_EQ(y.Value(), 0);
|
||||
}
|
||||
|
||||
{
|
||||
Azure::Nullable<int> z = 42;
|
||||
EXPECT_TRUE(z.HasValue());
|
||||
EXPECT_EQ(z.Value(), 42);
|
||||
EXPECT_EQ(z.Emplace(), 0);
|
||||
EXPECT_TRUE(z.HasValue());
|
||||
EXPECT_EQ(z.Value(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Nullable, Swap)
|
||||
{
|
||||
Nullable<int> val1;
|
||||
|
|
Загрузка…
Ссылка в новой задаче