+2019-04-17 Jonathan Wakely <jwakely@redhat.com>
+
+ * include/std/optional (optional::value_or(U&&) &&): Add missing
+ constexpr specifier.
+ * testsuite/20_util/optional/constexpr/observers/4.cc: Check value_or
+ for disengaged optionals and rvalue optionals.
+ * testsuite/20_util/optional/observers/4.cc: Likewise.
+
2019-04-12 Thomas Rodgers <trodgers@redhat.com>
* include/pstl/algorithm_impl.h: Uglify identfiers.
}
template<typename _Up>
- _Tp
+ constexpr _Tp
value_or(_Up&& __u) &&
{
static_assert(is_move_constructible_v<_Tp>);
int i;
};
-int main()
+void test01()
{
constexpr std::optional<value_type> o { value_type { 51 } };
constexpr value_type fallback { 3 };
- static_assert( o.value_or(fallback).i == 51, "" );
- static_assert( o.value_or(fallback).i == (*o).i, "" );
+ static_assert( o.value_or(fallback).i == 51 );
+ static_assert( o.value_or(fallback).i == (*o).i );
+}
+
+void test02()
+{
+ constexpr std::optional<value_type> o;
+ constexpr value_type fallback { 3 };
+ static_assert( o.value_or(fallback).i == 3 );
+}
+
+template<typename T>
+ constexpr std::optional<value_type>
+ make_rvalue(T t)
+ { return std::optional<value_type>{t}; }
+
+void test03()
+{
+ constexpr value_type fallback { 3 };
+ static_assert( make_rvalue(value_type{51}).value_or(fallback).i == 51 );
+}
+
+void test04()
+{
+ constexpr value_type fallback { 3 };
+ static_assert( make_rvalue(std::nullopt).value_or(fallback).i == 3 );
+}
+
+int main()
+{
+ test01();
+ test02();
+ test03();
+ test04();
}
int i;
};
-int main()
+void test01()
{
std::optional<value_type> o { value_type { 51 } };
value_type fallback { 3 };
VERIFY( o.value_or(fallback).i == 51 );
VERIFY( o.value_or(fallback).i == (*o).i );
}
+
+void test02()
+{
+ std::optional<value_type> o;
+ value_type fallback { 3 };
+ VERIFY( o.value_or(fallback).i == 3 );
+}
+
+void test03()
+{
+ std::optional<value_type> o { value_type { 51 } };
+ value_type fallback { 3 };
+ VERIFY( std::move(o).value_or(fallback).i == 51 );
+ VERIFY( o.has_value() );
+ VERIFY( std::move(o).value_or(fallback).i == (*o).i );
+}
+
+void test04()
+{
+ std::optional<value_type> o;
+ value_type fallback { 3 };
+ VERIFY( std::move(o).value_or(fallback).i == 3 );
+ VERIFY( !o.has_value() );
+}
+
+int main()
+{
+ test01();
+ test02();
+ test03();
+ test04();
+}