std::vector::vector

您所在的位置:网站首页 stdvector赋值 std::vector::vector

std::vector::vector

2024-07-09 03:09:02| 来源: 网络整理| 查看: 265

[edit template]  C++ Compiler support Freestanding and hosted Language Standard library Standard library headers Named requirements Feature test macros (C++20) Language support library Concepts library (C++20) Metaprogramming library (C++11) Diagnostics library General utilities library Strings library Containers library Iterators library Ranges library (C++20) Algorithms library Numerics library Localizations library Input/output library Filesystem library (C++17) Regular expressions library (C++11) Concurrency support library (C++11) Technical specifications Symbols index External libraries [edit] Containers library Sequence array(C++11) vector vector inplace_vector(C++26) deque forward_list(C++11) list Associative set multiset map multimap Unordered associative unordered_set(C++11) unordered_multiset(C++11) unordered_map(C++11) unordered_multimap(C++11) Adaptors stack queue priority_queue flat_set(C++23) flat_multiset(C++23) flat_map(C++23) flat_multimap(C++23) Views span(C++20) mdspan(C++23) Iterator invalidation Member function table Non-member function table [edit] std::vector Member types Member functions vector::vector vector::~vector vector::operator= vector::assign vector::assign_range(C++23) vector::get_allocator Element access vector::at vector::operator[] vector::front vector::back vector::data Iterators vector::beginvector::cbegin(C++11) vector::endvector::cend(C++11) vector::rbeginvector::crbegin(C++11) vector::rendvector::crend(C++11) Capacity vector::empty vector::size vector::max_size vector::reserve vector::capacity vector::shrink_to_fit(DR*) Modifiers vector::clear vector::insert vector::emplace(C++11) vector::insert_range(C++23)   vector::erase vector::push_back vector::emplace_back(C++11) vector::append_range(C++23) vector::pop_back vector::resize vector::swap Non-member functions operator==operator!=operatoroperator=operator(until C++20)(until C++20)(until C++20)(until C++20)(until C++20)(C++20) swap(std::vector) erase(std::vector)erase_if(std::vector)(C++20)(C++20) Deduction guides(C++17) [edit]  (1) vector(); (until C++17) vector() noexcept(noexcept(Allocator())); (since C++17) (constexpr since C++20) (2) explicit vector( const Allocator& alloc ); (until C++17) explicit vector( const Allocator& alloc ) noexcept; (since C++17) (constexpr since C++20) (3) explicit vector( size_type count,

                 const T& value = T(),

                 const Allocator& alloc = Allocator() ); (until C++11) vector( size_type count,

        const T& value,

        const Allocator& alloc = Allocator() ); (since C++11) (constexpr since C++20) (4) explicit vector( size_type count ); (since C++11) (until C++14) explicit vector( size_type count,                  const Allocator& alloc = Allocator() ); (since C++14) template

vector( InputIt first, InputIt last,

        const Allocator& alloc = Allocator() ); (5) (constexpr since C++20) vector( const vector& other ); (6) (constexpr since C++20) vector( const vector& other, const Allocator& alloc ); (7) (since C++11) (constexpr since C++20) vector( vector&& other ); (8) (since C++11) (noexcept since C++17)(constexpr since C++20) vector( vector&& other, const Allocator& alloc ); (9) (since C++11) (constexpr since C++20) vector( std::initializer_list init,         const Allocator& alloc = Allocator() ); (10) (since C++11) (constexpr since C++20) template

constexpr vector( std::from_range_t, R&& rg,

                  const Allocator& alloc = Allocator() ); (11) (since C++23)

Constructs a new container from a variety of data sources, optionally using a user supplied allocator alloc.

1) Default constructor. Constructs an empty container with a default-constructed allocator. 2) Constructs an empty container with the given allocator alloc. 3) Constructs the container with count copies of elements with value value. 4) Constructs the container with count default-inserted instances of T. No copies are made. 5) Constructs the container with the contents of the range [first, last).

This constructor has the same effect as vector(static_cast(first), static_cast(last), a) if InputIt is an integral type.

(until C++11)

This overload participates in overload resolution only if InputIt satisfies LegacyInputIterator, to avoid ambiguity with the overload (3).

(since C++11) 6) Copy constructor. Constructs the container with the copy of the contents of other.

The allocator is obtained as if by calling std::allocator_traits::select_on_container_copy_construction(    other.get_allocator()).

(since C++11) 7) Constructs the container with the copy of the contents of other, using alloc as the allocator.

During class template argument deduction, only the first argument contributes to the deduction of the container's Allocator template parameter.

(since C++23) 8) Move constructor. Constructs the container with the contents of other using move semantics. Allocator is obtained by move-construction from the allocator belonging to other. After the move, other is guaranteed to be empty(). 9) Allocator-extended move constructor. Using alloc as the allocator for the new container, moving the contents from other; if alloc != other.get_allocator(), this results in an element-wise move. (In that case, other is not guaranteed to be empty after the move.)

During class template argument deduction, only the first argument contributes to the deduction of the container's Allocator template parameter.

(since C++23) 10) Constructs the container with the contents of the initializer list init. 11) Constructs the container with the contents of the range rg. Contents 1 Parameters 2 Complexity 3 Exceptions 4 Notes 5 Example 6 Defect reports 7 See also [edit] Parameters alloc - allocator to use for all memory allocations of this container count - the size of the container value - the value to initialize elements of the container with first, last - the range [first, last) to copy the elements from other - another container to be used as source to initialize the elements of the container with init - initializer list to initialize the elements of the container with rg - a container compatible range, that is, an input_range whose elements are convertible to T [edit] Complexity 1,2) Constant. 3,4) Linear in count. 5) Given the distance between first and last as N, If first and last are both forward, bidirectional or random-access iterators, The copy constructor of T is only called N  times, and No reallocation occurs. Otherwise (first and last are just input iterators), The copy constructor of T is called O(N) times, and Reallocation occurs O(log N) times. 6,7) Linear in size of other. 8) Constant. 9) Linear if alloc != other.get_allocator(), otherwise constant. 10) Linear in size of init. 11) Given ranges::distance(rg) as N, If R models ranges::forward_range or ranges::sized_range, Initializes exactly N elements from the result of dereferencing successive iterators of rg, and No reallocation occurs. Otherwise (R models input range), The copy or move constructor of T is called O(N) times, and Reallocation occurs O(log N) times. [edit] Exceptions

Calls to Allocator::allocate may throw.

[edit] Notes

After container move construction (overload (8)), references, pointers, and iterators (other than the end iterator) to other remain valid, but refer to elements that are now in *this. The current standard makes this guarantee via the blanket statement in [container.reqmts]/67, and a more direct guarantee is under consideration via LWG issue 2321.

The overload (4) zeroes out elements of non-class types such as int, which is different from the behavior of new[], which leaves them uninitialized. To match the behavior of new[], a custom Allocator::construct can be provided which leaves such elements uninitialized.

Note that the presence of list-initializing constructor (10) means list initialization and direct initialization do different things:

std::vector b{3}; // creates a 1-element vector holding {3} std::vector d(3); // creates a 3-element vector holding {0, 0, 0}   std::vector p{1, 2}; // creates a 2-element vector holding {1, 2} std::vector q(1, 2); // creates a 1-element vector holding {2} Feature-test macro Value Std Feature __cpp_lib_containers_ranges 202202L (C++23) Ranges-aware construction and insertion; overload (11) [edit] Example Run this code #include #include #include   template std::ostream& operator


【本文地址】

公司简介

联系我们

今日新闻


点击排行

实验室常用的仪器、试剂和
说到实验室常用到的东西,主要就分为仪器、试剂和耗
不用再找了,全球10大实验
01、赛默飞世尔科技(热电)Thermo Fisher Scientif
三代水柜的量产巅峰T-72坦
作者:寞寒最近,西边闹腾挺大,本来小寞以为忙完这
通风柜跟实验室通风系统有
说到通风柜跟实验室通风,不少人都纠结二者到底是不
集消毒杀菌、烘干收纳为一
厨房是家里细菌较多的地方,潮湿的环境、没有完全密
实验室设备之全钢实验台如
全钢实验台是实验室家具中较为重要的家具之一,很多

推荐新闻


图片新闻

实验室药品柜的特性有哪些
实验室药品柜是实验室家具的重要组成部分之一,主要
小学科学实验中有哪些教学
计算机 计算器 一般 打孔器 打气筒 仪器车 显微镜
实验室各种仪器原理动图讲
1.紫外分光光谱UV分析原理:吸收紫外光能量,引起分
高中化学常见仪器及实验装
1、可加热仪器:2、计量仪器:(1)仪器A的名称:量
微生物操作主要设备和器具
今天盘点一下微生物操作主要设备和器具,别嫌我啰嗦
浅谈通风柜使用基本常识
 众所周知,通风柜功能中最主要的就是排气功能。在

专题文章

    CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭