libc++ implements its' hash objects as deriving from std::unary_function, and the tests test for that. STL @ MS pointed out that the standard doesn't requie these objects to derive from unary_function, and so the tests should not require that either. Change the tests to check for the embedded typedefs - which ARE required. No change to the library.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@225403 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Marshall Clow 2015-01-07 21:53:23 +00:00
parent 87d03942c4
commit 674e07d3c8
11 changed files with 35 additions and 24 deletions

View File

@ -29,8 +29,9 @@ int main()
{ {
typedef std::vector<bool> T; typedef std::vector<bool> T;
typedef std::hash<T> H; typedef std::hash<T> H;
static_assert((std::is_base_of<std::unary_function<T, std::size_t>, static_assert((std::is_same<H::argument_type, T>::value), "" );
H>::value), ""); static_assert((std::is_same<H::result_type, std::size_t>::value), "" );
bool ba[] = {true, false, true, true, false}; bool ba[] = {true, false, true, true, false};
T vb(std::begin(ba), std::end(ba)); T vb(std::begin(ba), std::end(ba));
H h; H h;

View File

@ -27,8 +27,8 @@ test(int i)
{ {
typedef std::error_code T; typedef std::error_code T;
typedef std::hash<T> H; typedef std::hash<T> H;
static_assert((std::is_base_of<std::unary_function<T, std::size_t>, static_assert((std::is_same<H::argument_type, T>::value), "" );
H>::value), ""); static_assert((std::is_same<H::result_type, std::size_t>::value), "" );
H h; H h;
T ec(i, std::system_category()); T ec(i, std::system_category());
assert(h(ec) == i); assert(h(ec) == i);

View File

@ -29,8 +29,8 @@ void
test() test()
{ {
typedef std::hash<T> H; typedef std::hash<T> H;
static_assert((std::is_base_of<std::unary_function<T, std::size_t>, static_assert((std::is_same<typename H::argument_type, T>::value), "" );
H>::value), ""); static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" );
H h; H h;
// std::string g1 = "1234567890"; // std::string g1 = "1234567890";
// std::string g2 = "1234567891"; // std::string g2 = "1234567891";

View File

@ -27,8 +27,8 @@ void
test() test()
{ {
typedef std::hash<T> H; typedef std::hash<T> H;
static_assert((std::is_base_of<std::unary_function<T, std::size_t>, static_assert((std::is_same<typename H::argument_type, T>::value), "" );
H>::value), ""); static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" );
H h; H h;
std::string g1 = "1234567890"; std::string g1 = "1234567890";
std::string g2 = "1234567891"; std::string g2 = "1234567891";

View File

@ -28,6 +28,8 @@ int main()
std::thread::id id1; std::thread::id id1;
std::thread::id id2 = std::this_thread::get_id(); std::thread::id id2 = std::this_thread::get_id();
typedef std::hash<std::thread::id> H; typedef std::hash<std::thread::id> H;
static_assert((std::is_same<typename H::argument_type, std::thread::id>::value), "" );
static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" );
H h; H h;
assert(h(id1) != h(id2)); assert(h(id1) != h(id2));
} }

View File

@ -33,11 +33,12 @@ template <class T>
void void
test() test()
{ {
static_assert((std::is_base_of<std::unary_function<T, std::size_t>, typedef std::hash<T> H;
std::hash<T> >::value), ""); static_assert((std::is_same<H::argument_type, T>::value), "" );
static_assert((std::is_same<H::result_type, std::size_t>::value), "" );
typedef typename std::underlying_type<T>::type under_type; typedef typename std::underlying_type<T>::type under_type;
std::hash<T> h1; H h1;
std::hash<under_type> h2; std::hash<under_type> h2;
for (int i = 0; i <= 5; ++i) for (int i = 0; i <= 5; ++i)
{ {

View File

@ -28,9 +28,11 @@ template <class T>
void void
test() test()
{ {
static_assert((std::is_base_of<std::unary_function<T, std::size_t>, typedef std::hash<T> H;
std::hash<T> >::value), ""); static_assert((std::is_same<typename H::argument_type, T>::value), "" );
std::hash<T> h; static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" );
H h;
std::size_t t0 = h(0.); std::size_t t0 = h(0.);
std::size_t tn0 = h(-0.); std::size_t tn0 = h(-0.);
std::size_t tp1 = h(0.1); std::size_t tp1 = h(0.1);

View File

@ -27,9 +27,11 @@ template <class T>
void void
test() test()
{ {
static_assert((std::is_base_of<std::unary_function<T, std::size_t>, typedef std::hash<T> H;
std::hash<T> >::value), ""); static_assert((std::is_same<typename H::argument_type, T>::value), "" );
std::hash<T> h; static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" );
H h;
for (int i = 0; i <= 5; ++i) for (int i = 0; i <= 5; ++i)
{ {
T t(i); T t(i);

View File

@ -27,9 +27,11 @@ template <class T>
void void
test() test()
{ {
static_assert((std::is_base_of<std::unary_function<T, std::size_t>, typedef std::hash<T> H;
std::hash<T> >::value), ""); static_assert((std::is_same<typename H::argument_type, T>::value), "" );
std::hash<T> h; static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" );
H h;
typedef typename std::remove_pointer<T>::type type; typedef typename std::remove_pointer<T>::type type;
type i; type i;
type j; type j;

View File

@ -28,8 +28,8 @@ test()
{ {
typedef std::bitset<N> T; typedef std::bitset<N> T;
typedef std::hash<T> H; typedef std::hash<T> H;
static_assert((std::is_base_of<std::unary_function<T, std::size_t>, static_assert((std::is_same<typename H::argument_type, T>::value), "" );
H>::value), ""); static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" );
H h; H h;
T bs(static_cast<unsigned long long>(N)); T bs(static_cast<unsigned long long>(N));
assert(h(bs) == N); assert(h(bs) == N);

View File

@ -20,6 +20,7 @@
int main() int main()
{ {
static_assert((std::is_base_of<std::unary_function<std::type_index, std::size_t>, typedef std::hash<std::type_index> H;
std::hash<std::type_index> >::value), ""); static_assert((std::is_same<typename H::argument_type, std::type_index>::value), "" );
static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" );
} }