brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.7 KiB · 5768495 Raw
96 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include <cstdint>10#include <vector>11 12#include "min_allocator.h"13#include "test_allocator.h"14#include "test_macros.h"15 16template <class T>17class small_pointer {18public:19  using value_type        = T;20  using difference_type   = std::int16_t;21  using pointer           = small_pointer;22  using reference         = T&;23  using iterator_category = std::random_access_iterator_tag;24 25private:26  std::uint16_t offset;27};28 29template <class T>30class small_iter_allocator {31public:32  using value_type      = T;33  using pointer         = small_pointer<T>;34  using size_type       = std::int16_t;35  using difference_type = std::int16_t;36 37  small_iter_allocator() TEST_NOEXCEPT {}38 39  template <class U>40  small_iter_allocator(small_iter_allocator<U>) TEST_NOEXCEPT {}41 42  T* allocate(std::size_t n);43  void deallocate(T* p, std::size_t);44 45  friend bool operator==(small_iter_allocator, small_iter_allocator) { return true; }46  friend bool operator!=(small_iter_allocator, small_iter_allocator) { return false; }47};48 49#if __SIZE_WIDTH__ == 6450 51static_assert(sizeof(std::vector<int>) == 24, "");52static_assert(sizeof(std::vector<int, min_allocator<int> >) == 24, "");53static_assert(sizeof(std::vector<int, test_allocator<int> >) == 40, "");54static_assert(sizeof(std::vector<int, small_iter_allocator<int> >) == 6, "");55 56static_assert(sizeof(std::vector<char>) == 24, "");57static_assert(sizeof(std::vector<char, min_allocator<char> >) == 24, "");58static_assert(sizeof(std::vector<char, test_allocator<char> >) == 40, "");59static_assert(sizeof(std::vector<char, small_iter_allocator<char> >) == 6, "");60 61static_assert(TEST_ALIGNOF(std::vector<int>) == 8, "");62static_assert(TEST_ALIGNOF(std::vector<int, min_allocator<int> >) == 8, "");63static_assert(TEST_ALIGNOF(std::vector<int, test_allocator<int> >) == 8, "");64static_assert(TEST_ALIGNOF(std::vector<int, small_iter_allocator<int> >) == 2, "");65 66static_assert(TEST_ALIGNOF(std::vector<char>) == 8, "");67static_assert(TEST_ALIGNOF(std::vector<char, min_allocator<char> >) == 8, "");68static_assert(TEST_ALIGNOF(std::vector<char, test_allocator<char> >) == 8, "");69static_assert(TEST_ALIGNOF(std::vector<char, small_iter_allocator<char> >) == 2, "");70 71#elif __SIZE_WIDTH__ == 3272 73static_assert(sizeof(std::vector<int>) == 12, "");74static_assert(sizeof(std::vector<int, min_allocator<int> >) == 12, "");75static_assert(sizeof(std::vector<int, test_allocator<int> >) == 24, "");76static_assert(sizeof(std::vector<int, small_iter_allocator<int> >) == 6, "");77 78static_assert(sizeof(std::vector<char>) == 12, "");79static_assert(sizeof(std::vector<char, min_allocator<char> >) == 12, "");80static_assert(sizeof(std::vector<char, test_allocator<char> >) == 24, "");81static_assert(sizeof(std::vector<char, small_iter_allocator<char> >) == 6, "");82 83static_assert(TEST_ALIGNOF(std::vector<int>) == 4, "");84static_assert(TEST_ALIGNOF(std::vector<int, min_allocator<int> >) == 4, "");85static_assert(TEST_ALIGNOF(std::vector<int, test_allocator<int> >) == 4, "");86static_assert(TEST_ALIGNOF(std::vector<int, small_iter_allocator<int> >) == 2, "");87 88static_assert(TEST_ALIGNOF(std::vector<char>) == 4, "");89static_assert(TEST_ALIGNOF(std::vector<char, min_allocator<char> >) == 4, "");90static_assert(TEST_ALIGNOF(std::vector<char, test_allocator<char> >) == 4, "");91static_assert(TEST_ALIGNOF(std::vector<char, small_iter_allocator<char> >) == 2, "");92 93#else94#  error std::size_t has an unexpected size95#endif96