110 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> deque(InputIterator f, InputIterator l);12 13#include "asan_testing.h"14#include <algorithm>15#include <deque>16#include <cassert>17#include <cstddef>18 19#include "test_macros.h"20#include "test_allocator.h"21#include "test_iterators.h"22#include "min_allocator.h"23#if TEST_STD_VER >= 1124# include "emplace_constructible.h"25#endif26 27template <class InputIterator>28void test(InputIterator f, InputIterator l) {29 typedef typename std::iterator_traits<InputIterator>::value_type T;30 typedef std::allocator<T> Allocator;31 typedef std::deque<T, Allocator> C;32 C d(f, l);33 assert(d.size() == static_cast<std::size_t>(std::distance(f, l)));34 assert(static_cast<std::size_t>(std::distance(d.begin(), d.end())) == d.size());35 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(d));36 assert(std::equal(d.begin(), d.end(), f));37}38 39template <class Allocator, class InputIterator>40void test(InputIterator f, InputIterator l) {41 typedef typename std::iterator_traits<InputIterator>::value_type T;42 typedef std::deque<T, Allocator> C;43 typedef typename C::const_iterator const_iterator;44 C d(f, l);45 assert(d.size() == static_cast<std::size_t>(std::distance(f, l)));46 assert(static_cast<std::size_t>(std::distance(d.begin(), d.end())) == d.size());47 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(d));48 for (const_iterator i = d.begin(), e = d.end(); i != e; ++i, ++f)49 assert(*i == *f);50}51 52void basic_test() {53 int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45};54 int* an = ab + sizeof(ab) / sizeof(ab[0]);55 test(cpp17_input_iterator<const int*>(ab), cpp17_input_iterator<const int*>(an));56 test(forward_iterator<const int*>(ab), forward_iterator<const int*>(an));57 test(bidirectional_iterator<const int*>(ab), bidirectional_iterator<const int*>(an));58 test(random_access_iterator<const int*>(ab), random_access_iterator<const int*>(an));59 test<limited_allocator<int, 4096> >(ab, an);60#if TEST_STD_VER >= 1161 test<min_allocator<int> >(ab, an);62#endif63}64 65void test_emplacable_concept() {66#if TEST_STD_VER >= 1167 int arr1[] = {42};68 int arr2[] = {1, 101, 42};69 {70 using T = EmplaceConstructibleAndMoveable<int>;71 using It = random_access_iterator<int*>;72 {73 std::deque<T> v(It(arr1), It(std::end(arr1)));74 assert(v[0].value == 42);75 }76 {77 std::deque<T> v(It(arr2), It(std::end(arr2)));78 assert(v[0].value == 1);79 assert(v[1].value == 101);80 assert(v[2].value == 42);81 }82 }83 {84 using T = EmplaceConstructibleAndMoveable<int>;85 using It = cpp17_input_iterator<int*>;86 {87 std::deque<T> v(It(arr1), It(std::end(arr1)));88 assert(v[0].copied == 0);89 assert(v[0].value == 42);90 }91 {92 std::deque<T> v(It(arr2), It(std::end(arr2)));93 //assert(v[0].copied == 0);94 assert(v[0].value == 1);95 //assert(v[1].copied == 0);96 assert(v[1].value == 101);97 assert(v[2].copied == 0);98 assert(v[2].value == 42);99 }100 }101#endif102}103 104int main(int, char**) {105 basic_test();106 test_emplacable_concept();107 108 return 0;109}110