Skip to content

Commit ab1aff3

Browse files
committed
Add test for std::hash<>
1 parent 891c9e0 commit ab1aff3

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,12 @@ value_ptr: Allows to obtain engaged state via operator bool()
4343
value_ptr: Allows to reset content
4444
value_ptr: Allows to swap with other value_ptr (member)
4545
value_ptr: Allows to swap with other value_ptr (non-member)
46-
value_ptr: Provides relational operators (pointer comparison)
46+
value_ptr: Provides relational operators (pointer comparison, non-member)
4747
make_value: Allows to copy-construct value_ptr
4848
make_value: Allows to move-construct value_ptr (C++11)
4949
make_value: Allows to in-place copy-construct value_ptr from arguments (C++11)
5050
make_value: Allows to in-place move-construct value_ptr from arguments (C++11)
5151
make_value: Allows to in-place copy-construct value_ptr from initializer-list and arguments (C++11)
5252
make_value: Allows to in-place move-construct value_ptr from initializer-list and arguments (C++11)
53+
std::hash<>: Allows to obtain hash (C++11)
5354
```

include/nonstd/value_ptr.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ struct hash< nonstd::value_ptr<T, D, C> >
940940

941941
result_type operator()( argument_type const & p ) const nsvp_noexcept
942942
{
943-
return hash<typename argument_type::pointer>()( p.get() );
943+
return hash<typename argument_type::const_pointer>()( p.get() );
944944
}
945945
};
946946

test/value-ptr.t.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ namespace {
666666
};
667667
}
668668

669-
CASE( "value_ptr: Provides relational operators (pointer comparison)" )
669+
CASE( "value_ptr: Provides relational operators (pointer comparison, non-member)" )
670670
{
671671
SETUP( "" ) {
672672

@@ -781,6 +781,20 @@ CASE( "make_value: Allows to in-place move-construct value_ptr from initializer-
781781
#endif
782782
}
783783

784+
CASE( "std::hash<>: Allows to obtain hash (C++11)" )
785+
{
786+
#if nsvp_CPP11_OR_GREATER
787+
value_ptr<int> a( 7 );
788+
value_ptr<int> b( 7 );
789+
790+
EXPECT( std::hash<value_ptr<int> >()( a ) == std::hash<value_ptr<int> >()( a ) );
791+
EXPECT( std::hash<value_ptr<int> >()( b ) == std::hash<value_ptr<int> >()( b ) );
792+
EXPECT( std::hash<value_ptr<int> >()( a ) != std::hash<value_ptr<int> >()( b ) );
793+
#else
794+
EXPECT( !!"std::hash<>: std::hash<> is not available (no C++11)" );
795+
#endif
796+
}
797+
784798
//------------------------------------------------------------------------
785799
// Applets:
786800

0 commit comments

Comments
 (0)