forked from boostorg/optional
fixed interop between opt refs and opt vals
This commit is contained in:
@ -79,6 +79,7 @@
|
||||
typedef T value_type ;
|
||||
typedef T & reference_type ;
|
||||
typedef T const& reference_const_type ;
|
||||
typedef T && rval_reference_type ;
|
||||
typedef T * pointer_type ;
|
||||
typedef T const* pointer_const_type ;
|
||||
|
||||
@ -182,6 +183,7 @@
|
||||
typedef T& value_type;
|
||||
typedef T& reference_type;
|
||||
typedef T& reference_const_type; // no const propagation
|
||||
typedef T& rval_reference_type;
|
||||
typedef T* pointer_type;
|
||||
typedef T* pointer_const_type; // no const propagation
|
||||
|
||||
|
@ -35,6 +35,7 @@
|
||||
<span class="keyword">typedef</span> <span class="identifier">T</span><span class="special">&</span> <span class="identifier">value_type</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">T</span><span class="special">&</span> <span class="identifier">reference_type</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">T</span><span class="special">&</span> <span class="identifier">reference_const_type</span><span class="special">;</span> <span class="comment">// no const propagation</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">T</span><span class="special">&</span> <span class="identifier">rval_reference_type</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">T</span><span class="special">*</span> <span class="identifier">pointer_type</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">T</span><span class="special">*</span> <span class="identifier">pointer_const_type</span><span class="special">;</span> <span class="comment">// no const propagation</span>
|
||||
|
||||
|
@ -35,6 +35,7 @@
|
||||
<span class="keyword">typedef</span> <span class="identifier">T</span> <span class="identifier">value_type</span> <span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">T</span> <span class="special">&</span> <span class="identifier">reference_type</span> <span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">T</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">reference_const_type</span> <span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">T</span> <span class="special">&&</span> <span class="identifier">rval_reference_type</span> <span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">T</span> <span class="special">*</span> <span class="identifier">pointer_type</span> <span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">T</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">pointer_const_type</span> <span class="special">;</span>
|
||||
|
||||
|
@ -144,7 +144,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"><p><small>Last revised: March 05, 2016 at 22:52:00 GMT</small></p></td>
|
||||
<td align="left"><p><small>Last revised: March 06, 2016 at 18:03:49 GMT</small></p></td>
|
||||
<td align="right"><div class="copyright-footer"></div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
|
@ -86,6 +86,7 @@ public:
|
||||
typedef T& value_type;
|
||||
typedef T& reference_type;
|
||||
typedef T& reference_const_type;
|
||||
typedef T& rval_reference_type;
|
||||
typedef T* pointer_type;
|
||||
typedef T* pointer_const_type;
|
||||
|
||||
|
@ -30,6 +30,7 @@ import testing ;
|
||||
[ run optional_test_ref_convert_assign_const_int.cpp ]
|
||||
[ run optional_test_ref_portable_minimum.cpp ]
|
||||
[ run optional_test_ref_move.cpp ]
|
||||
[ run optional_test_ref_to_val.cpp ]
|
||||
[ run optional_test_inplace_factory.cpp ]
|
||||
[ run optional_test_io.cpp ]
|
||||
[ run optional_test_move.cpp ]
|
||||
|
116
test/optional_test_ref_to_val.cpp
Normal file
116
test/optional_test_ref_to_val.cpp
Normal file
@ -0,0 +1,116 @@
|
||||
// Copyright (C) 2016 Andrzej Krzemienski.
|
||||
//
|
||||
// Use, modification, and distribution is subject to the Boost Software
|
||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See http://www.boost.org/lib/optional for documentation.
|
||||
//
|
||||
// You are welcome to contact the author at:
|
||||
// akrzemi1@gmail.com
|
||||
|
||||
|
||||
#include "boost/optional/optional.hpp"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "boost/core/lightweight_test.hpp"
|
||||
|
||||
using boost::optional;
|
||||
using boost::none;
|
||||
|
||||
struct Value
|
||||
{
|
||||
int val;
|
||||
explicit Value(int v) : val(v) {}
|
||||
};
|
||||
|
||||
int val(int const& i)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
|
||||
int val(Value const& v)
|
||||
{
|
||||
return v.val;
|
||||
}
|
||||
|
||||
template <typename Tref>
|
||||
optional<Tref&> make_opt_ref(Tref& v)
|
||||
{
|
||||
return optional<Tref&>(v);
|
||||
}
|
||||
|
||||
template <typename Tval, typename Tref>
|
||||
void test_construct_from_optional_ref()
|
||||
{
|
||||
Tref v1 (1), v2 (2);
|
||||
|
||||
optional<Tref&> opt_ref0;
|
||||
optional<Tref&> opt_ref1 (v1);
|
||||
|
||||
optional<Tval> opt_val0 (opt_ref0);
|
||||
optional<Tval> opt_val1 (opt_ref1);
|
||||
optional<Tval> opt_val2 (make_opt_ref(v2));
|
||||
|
||||
BOOST_TEST (!opt_val0);
|
||||
BOOST_TEST (opt_val1);
|
||||
BOOST_TEST (opt_val2);
|
||||
|
||||
BOOST_TEST_EQ (1, val(*opt_val1));
|
||||
BOOST_TEST_EQ (2, val(*opt_val2));
|
||||
|
||||
BOOST_TEST (boost::addressof(*opt_val1) != boost::addressof(v1));
|
||||
BOOST_TEST (boost::addressof(*opt_val2) != boost::addressof(v2));
|
||||
}
|
||||
|
||||
template <typename Tval, typename Tref>
|
||||
void test_assign_from_optional_ref()
|
||||
{
|
||||
Tref v1 (1), v2 (2);
|
||||
|
||||
optional<Tref&> opt_ref0;
|
||||
optional<Tref&> opt_ref1 (v1);
|
||||
|
||||
optional<Tval> opt_val0;
|
||||
optional<Tval> opt_val1;
|
||||
optional<Tval> opt_val2;
|
||||
|
||||
opt_val0 = opt_ref0;
|
||||
opt_val1 = opt_ref1;
|
||||
opt_val2 = make_opt_ref(v2);
|
||||
|
||||
BOOST_TEST (!opt_val0);
|
||||
BOOST_TEST (opt_val1);
|
||||
BOOST_TEST (opt_val2);
|
||||
|
||||
BOOST_TEST_EQ (1, val(*opt_val1));
|
||||
BOOST_TEST_EQ (2, val(*opt_val2));
|
||||
|
||||
BOOST_TEST (boost::addressof(*opt_val1) != boost::addressof(v1));
|
||||
BOOST_TEST (boost::addressof(*opt_val2) != boost::addressof(v2));
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
test_construct_from_optional_ref<int, int>();
|
||||
test_construct_from_optional_ref<int, int const>();
|
||||
test_construct_from_optional_ref<int const, int const>();
|
||||
test_construct_from_optional_ref<int const, int>();
|
||||
|
||||
test_construct_from_optional_ref<Value, Value>();
|
||||
test_construct_from_optional_ref<Value, Value const>();
|
||||
test_construct_from_optional_ref<Value const, Value const>();
|
||||
test_construct_from_optional_ref<Value const, Value>();
|
||||
|
||||
test_assign_from_optional_ref<int, int>();
|
||||
test_assign_from_optional_ref<int, int const>();
|
||||
|
||||
test_assign_from_optional_ref<Value, Value>();
|
||||
test_assign_from_optional_ref<Value, Value const>();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
Reference in New Issue
Block a user