fix optional converting constructor

This commit is contained in:
bolero-MURAKAMI 2012-10-27 15:53:34 +09:00
parent 5aa4cf8cbe
commit d75283355c
2 changed files with 36 additions and 1 deletions

View file

@ -303,6 +303,41 @@ namespace testspr {
is >> opt3; is >> opt3;
TESTSPR_ASSERT(!opt3); TESTSPR_ASSERT(!opt3);
} }
// get
TESTSPR_BOTH_ASSERT(sprout::get(opt1) == 1234);
{
auto opt3 = sprout::optional<int>(1234);
TESTSPR_ASSERT(sprout::get(opt3) == 1234);
opt3.get() = 12345;
TESTSPR_ASSERT(sprout::get(opt3) == 12345);
}
// get_pointer
TESTSPR_BOTH_ASSERT(*sprout::get_pointer(opt1) == 1234);
{
auto opt3 = sprout::optional<int>(1234);
TESTSPR_ASSERT(*sprout::get_pointer(opt3) == 1234);
opt3.get() = 12345;
TESTSPR_ASSERT(*sprout::get_pointer(opt3) == 12345);
}
// get_optional_value_or
TESTSPR_BOTH_ASSERT(sprout::get_optional_value_or(opt1, 12345) == 1234);
TESTSPR_BOTH_ASSERT(sprout::get_optional_value_or(opt2, 12345) == 12345);
{
auto opt3 = sprout::optional<int>(1234);
int v = 12345;
TESTSPR_ASSERT(sprout::get_optional_value_or(opt3, v) == 1234);
}
{
auto opt3 = sprout::optional<int>();
int v = 12345;
TESTSPR_ASSERT(sprout::get_optional_value_or(opt3, v) == 12345);
}
} }
} }
} // namespace testspr } // namespace testspr

View file

@ -58,7 +58,7 @@ namespace sprout {
template<typename U> template<typename U>
explicit SPROUT_CONSTEXPR optional(optional<U> const& v) explicit SPROUT_CONSTEXPR optional(optional<U> const& v)
: init(v.is_initialized()) : init(v.is_initialized())
, val(v.get()) , val(v.is_initialized() ? v.get() : holder_type())
{} {}
optional& operator=(sprout::nullopt_t v) SPROUT_NOEXCEPT { optional& operator=(sprout::nullopt_t v) SPROUT_NOEXCEPT {