mirror of
https://github.com/llvm-mirror/libcxx.git
synced 2025-10-24 03:32:35 +08:00

Summary: The `max_size()` method of containers should respect both the allocator's reported `max_size` and the range of the `difference_type`. This patch makes all containers choose the smallest of those two values. Reviewers: mclow.lists, EricWF Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D26885 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@287729 91177308-0d34-0410-b5e6-96231b3b80d8
52 lines
1.3 KiB
C++
52 lines
1.3 KiB
C++
//===----------------------------------------------------------------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
|
// Source Licenses. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// <map>
|
|
|
|
// class multimap
|
|
|
|
// size_type max_size() const;
|
|
|
|
#include <cassert>
|
|
#include <limits>
|
|
#include <map>
|
|
#include <type_traits>
|
|
|
|
#include "test_allocator.h"
|
|
#include "test_macros.h"
|
|
|
|
int main()
|
|
{
|
|
typedef std::pair<const int, int> KV;
|
|
{
|
|
typedef limited_allocator<KV, 10> A;
|
|
typedef std::multimap<int, int, std::less<int>, A> C;
|
|
C c;
|
|
assert(c.max_size() <= 10);
|
|
LIBCPP_ASSERT(c.max_size() == 10);
|
|
}
|
|
{
|
|
typedef limited_allocator<KV, (size_t)-1> A;
|
|
typedef std::multimap<int, int, std::less<int>, A> C;
|
|
const C::difference_type max_dist =
|
|
std::numeric_limits<C::difference_type>::max();
|
|
C c;
|
|
assert(c.max_size() <= max_dist);
|
|
LIBCPP_ASSERT(c.max_size() == max_dist);
|
|
}
|
|
{
|
|
typedef std::multimap<char, int> C;
|
|
const C::difference_type max_dist =
|
|
std::numeric_limits<C::difference_type>::max();
|
|
C c;
|
|
assert(c.max_size() <= max_dist);
|
|
assert(c.max_size() <= alloc_max_size(c.get_allocator()));
|
|
}
|
|
}
|