brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.7 KiB · ef876bb Raw
106 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// <deque>10 11// template <class InputIterator>12//   deque(InputIterator f, InputIterator l, const allocator_type& a);13 14#include "asan_testing.h"15#include <algorithm>16#include <deque>17#include <cassert>18#include <cstddef>19 20#include "test_macros.h"21#include "test_iterators.h"22#include "test_allocator.h"23#include "min_allocator.h"24#if TEST_STD_VER >= 1125#  include "emplace_constructible.h"26#endif27 28template <class InputIterator, class Allocator>29void test(InputIterator f, InputIterator l, const Allocator& a) {30  typedef typename std::iterator_traits<InputIterator>::value_type T;31  typedef std::deque<T, Allocator> C;32  C d(f, l, a);33  assert(d.get_allocator() == a);34  assert(d.size() == static_cast<std::size_t>(std::distance(f, l)));35  assert(static_cast<std::size_t>(std::distance(d.begin(), d.end())) == d.size());36  LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(d));37  assert(std::equal(d.begin(), d.end(), f));38}39 40void basic_test() {41  int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45};42  int* an  = ab + sizeof(ab) / sizeof(ab[0]);43  test(cpp17_input_iterator<const int*>(ab), cpp17_input_iterator<const int*>(an), test_allocator<int>(3));44  test(forward_iterator<const int*>(ab), forward_iterator<const int*>(an), test_allocator<int>(4));45  test(bidirectional_iterator<const int*>(ab), bidirectional_iterator<const int*>(an), test_allocator<int>(5));46  test(random_access_iterator<const int*>(ab), random_access_iterator<const int*>(an), test_allocator<int>(6));47#if TEST_STD_VER >= 1148  test(cpp17_input_iterator<const int*>(ab), cpp17_input_iterator<const int*>(an), min_allocator<int>());49  test(forward_iterator<const int*>(ab), forward_iterator<const int*>(an), min_allocator<int>());50  test(bidirectional_iterator<const int*>(ab), bidirectional_iterator<const int*>(an), min_allocator<int>());51  test(random_access_iterator<const int*>(ab), random_access_iterator<const int*>(an), min_allocator<int>());52#endif53}54 55void test_emplacable_concept() {56#if TEST_STD_VER >= 1157  int arr1[] = {42};58  int arr2[] = {1, 101, 42};59  {60    using T  = EmplaceConstructibleAndMoveable<int>;61    using It = random_access_iterator<int*>;62    std::allocator<T> a;63    {64      std::deque<T> v(It(arr1), It(std::end(arr1)), a);65      assert(v[0].value == 42);66      LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(v));67    }68    {69      std::deque<T> v(It(arr2), It(std::end(arr2)), a);70      assert(v[0].value == 1);71      assert(v[1].value == 101);72      assert(v[2].value == 42);73      LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(v));74    }75  }76  {77    using T  = EmplaceConstructibleAndMoveable<int>;78    using It = cpp17_input_iterator<int*>;79    std::allocator<T> a;80    {81      std::deque<T> v(It(arr1), It(std::end(arr1)), a);82      assert(v[0].copied == 0);83      assert(v[0].value == 42);84      LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(v));85    }86    {87      std::deque<T> v(It(arr2), It(std::end(arr2)), a);88      //assert(v[0].copied == 0);89      assert(v[0].value == 1);90      //assert(v[1].copied == 0);91      assert(v[1].value == 101);92      assert(v[2].copied == 0);93      assert(v[2].value == 42);94      LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(v));95    }96  }97#endif98}99 100int main(int, char**) {101  basic_test();102  test_emplacable_concept();103 104  return 0;105}106