Skip to content

Commit dec7857

Browse files
committed
Test const correctness of projection member functions in result_and_mfn1v.cpp
1 parent c8e1b9f commit dec7857

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

test/result_and_mfn1v.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ struct X
1515
X( int v ): v_( v ) {}
1616

1717
int f() const { return v_; }
18+
1819
void g() const { ++g_called_; }
20+
21+
int& h() { return v_; }
22+
int const& h2() const { return v_; }
1923
};
2024

2125
struct E
@@ -206,5 +210,45 @@ int main()
206210
BOOST_TEST( r2.has_error() );
207211
}
208212

213+
{
214+
result<X> r( 1 );
215+
result<int&> r2 = r & &X::h;
216+
217+
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( *r2, 1 );
218+
}
219+
220+
{
221+
result<X> const r( 1 );
222+
result<int const&> r2 = r & &X::h2;
223+
224+
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( *r2, 1 );
225+
}
226+
227+
{
228+
result<int> r2 = result<X>( 1 ) & &X::h2;
229+
230+
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( *r2, 1 );
231+
}
232+
233+
{
234+
result<X, E> r( in_place_error );
235+
result<int&, E> r2 = r & &X::h;
236+
237+
BOOST_TEST( r2.has_error() );
238+
}
239+
240+
{
241+
result<X, E> const r( in_place_error );
242+
result<int const&, E> r2 = r & &X::h2;
243+
244+
BOOST_TEST( r2.has_error() );
245+
}
246+
247+
{
248+
result<int, E> r2 = result<X, E>( in_place_error ) & &X::h2;
249+
250+
BOOST_TEST( r2.has_error() );
251+
}
252+
209253
return boost::report_errors();
210254
}

0 commit comments

Comments
 (0)