Namespaces
Variants
Views
Actions

Difference between revisions of "Template:cpp/container/begin"

From cppreference.com
m (Behold the versioning (1)/(2)/(3). Testing...)
 
(17 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{#switch:{{{1|}}}|span={{cpp/container/{{{1|}}}/title|begin}}
+
{{#vardefine:cont|{{{1|inplace_vector}}}}}<!--
|#default={{cpp/container/{{{1|}}}/title|begin|cbegin}}
+
-->{{cpp/container/{{#var:cont}}/title|begin|cbegin}}
}}
+
{{cpp/container/{{#var:cont}}/navbar}}
{{cpp/container/{{{1|}}}/navbar}}
+
 
{{dcl begin}}
 
{{dcl begin}}
{{#switch:{{{1|}}}|array=
+
{{#switch:{{#var:cont}}
{{dcl rev multi|num=1
+
|array=
|until1=c++17|dcl1=
+
{{dcl|num=1|since=c++11|notes={{mark constexpr since c++17}}|
 
iterator begin() noexcept;
 
iterator begin() noexcept;
|dcl2=
 
constexpr iterator begin() noexcept;
 
 
}}
 
}}
{{dcl rev multi|num=2
+
{{dcl|num=2|since=c++11|notes={{mark constexpr since c++17}}|
|until1=c++17|dcl1=
+
 
const_iterator begin() const noexcept;
 
const_iterator begin() const noexcept;
|dcl2=
 
constexpr const_iterator begin() const noexcept;
 
 
}}
 
}}
{{dcl rev multi|num=3
+
{{dcl|num=3|since=c++11|notes={{mark constexpr since c++17}}|
|until1=c++17|dcl1=
+
 
const_iterator cbegin() const noexcept;
 
const_iterator cbegin() const noexcept;
|dcl2=
 
constexpr const_iterator cbegin() const noexcept;
 
 
}}
 
}}
 
|vector=
 
|vector=
{{dcl rev multi|num=1
+
{{dcl|num=1|notes={{mark noexcept since c++11}}<br>{{mark constexpr since c++20}}|
|until1=c++11|dcl1=
+
 
iterator begin();
 
iterator begin();
|until2=c++20|dcl2=
 
iterator begin() noexcept;
 
|dcl3=
 
constexpr iterator begin() noexcept;
 
 
}}
 
}}
{{dcl rev multi|num=2
+
{{dcl|num=2|notes={{mark noexcept since c++11}}<br>{{mark constexpr since c++20}}|
|until1=c++11|dcl1=
+
 
const_iterator begin() const;
 
const_iterator begin() const;
|until2=c++20|dcl2=
 
const_iterator begin() const noexcept;
 
|dcl3=
 
constexpr const_iterator begin() const noexcept;
 
 
}}
 
}}
{{dcl rev multi|num=3
+
{{dcl|num=3|since=c++11|notes={{mark constexpr since c++20}}|
|since1=c++11|until1=c++20|dcl1=
+
 
const_iterator cbegin() const noexcept;
 
const_iterator cbegin() const noexcept;
|dcl2=
+
}}
 +
|inplace_vector=
 +
{{dcl|num=1|since=c++26|
 +
constexpr iterator begin() noexcept;
 +
}}
 +
{{dcl|num=2|since=c++26|
 +
constexpr const_iterator begin() const noexcept;
 +
}}
 +
{{dcl|num=3|since=c++26|
 
constexpr const_iterator cbegin() const noexcept;
 
constexpr const_iterator cbegin() const noexcept;
 
}}
 
}}
 
|span=
 
|span=
{{dcl|
+
{{dcl|num=1|since=c++20|
 
constexpr iterator begin() const noexcept;
 
constexpr iterator begin() const noexcept;
 
}}
 
}}
|{{dcl begin}}
+
{{dcl|num=2|since=c++23|
{{cpp/container/noexcept dcl|num=1|{{{1|}}}|dcl=
+
constexpr const_iterator cbegin() const noexcept;
 +
}}
 +
|flat_map|flat_multimap|flat_set|flat_multiset=
 +
{{dcl|num=1|since=c++23|
 +
iterator begin() noexcept;
 +
}}
 +
{{dcl|num=2|since=c++23|
 +
const_iterator begin() const noexcept;
 +
}}
 +
{{dcl|num=3|since=c++23|
 +
const_iterator cbegin() const noexcept;
 +
}}
 +
|
 +
{{cpp/container/noexcept dcl|num=1|{{#var:cont}}|dcl=
 
iterator begin()
 
iterator begin()
 
}}
 
}}
{{cpp/container/noexcept dcl|num=2|{{{1|}}}|dcl=
+
{{cpp/container/noexcept dcl|num=2|{{#var:cont}}|dcl=
 
const_iterator begin() const
 
const_iterator begin() const
 
}}
 
}}
{{dcl|num=3|since={{cpp/std|{{{1|}}}|c++11}}|
+
{{dcl|num=3|since={{cpp/std|{{#var:cont}}|c++11}}|
 
const_iterator cbegin() const noexcept;
 
const_iterator cbegin() const noexcept;
 
}}
 
}}
Line 63: Line 64:
 
{{dcl end}}
 
{{dcl end}}
  
Returns an iterator to the first element of the {{tt|{{{1}}}}}.
+
Returns an iterator to the first element of the {{tt|{{#var:cont}}}}.
  
If the {{tt|{{{1}}}}} is empty, the returned iterator will be equal to {{lc|end()}}.
+
If the {{tt|{{#var:cont}}}} is empty, the returned iterator will be equal to {{lc|end()}}.
  
 
{{image|range-begin-end.svg}}
 
{{image|range-begin-end.svg}}
Line 77: Line 78:
 
===Complexity===
 
===Complexity===
 
Constant.
 
Constant.
{{#if:{{#pos:{{{1}}}|set}}|{{cpp/container/constant iterator note}}}}
+
<!---->
 
+
{{#ifexpr:{{cpp/container/if c++98|{{#var:cont}}|1|0}}or{{cpp/container/if set|{{#var:cont}}|1|0}}|
 +
===Notes===
 +
{{cpp/container/if set|{{#var:cont}}|{{cpp/container/constant iterator note}}}}
 +
{{cpp/container/if c++98|{{#var:cont}}|<p>libc++ backports {{tt|cbegin()}} to C++98 mode.</p>}}}}
 +
<!---->
 
===Example===
 
===Example===
{{#switch:{{{1}}}
+
{{#switch:{{#var:cont}}
|deque|forward_list|list|vector={{cpp/container/begin/examples/sequence|{{{1}}}}}
+
|deque|forward_list|list|vector={{cpp/container/begin/examples/sequence|{{#var:cont}}}}
|{{cpp/container/begin/examples/{{{1}}}}}
+
|{{cpp/container/begin/examples/{{#var:cont}}}}
 
}}
 
}}
  
 
===See also===
 
===See also===
 
{{dsc begin}}
 
{{dsc begin}}
{{dsc inc|cpp/container/dsc end|{{{1|}}}}}
+
{{dsc inc|cpp/container/dsc end|{{#var:cont}}}}
 
{{dsc inc|cpp/iterator/dsc begin}}
 
{{dsc inc|cpp/iterator/dsc begin}}
 
{{dsc end}}
 
{{dsc end}}

Latest revision as of 05:07, 16 August 2024

 
 
 
 
constexpr iterator begin() noexcept;
(1) (since C++26)
constexpr const_iterator begin() const noexcept;
(2) (since C++26)
constexpr const_iterator cbegin() const noexcept;
(3) (since C++26)

Returns an iterator to the first element of the inplace_vector.

If the inplace_vector is empty, the returned iterator will be equal to end().

range-begin-end.svg

Contents

[edit] Parameters

(none)

[edit] Return value

Iterator to the first element.

[edit] Complexity

Constant.

[edit] Example

Template:cpp/container/begin/examples/inplace vector

[edit] See also

returns an iterator to the end
(public member function of std::inplace_vector<T,N>) [edit]
(C++11)(C++14)
returns an iterator to the beginning of a container or array
(function template) [edit]