Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/iterator/ranges/iter move"

From cppreference.com
< cpp‎ | iterator
m
m (Removed 't', it only exists in the call signature.)
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{cpp/ranges/title | iter_move}}
+
{{cpp/ranges/title|iter_move}}
 
{{cpp/iterator/navbar}}
 
{{cpp/iterator/navbar}}
  
 
{{dcl begin}}
 
{{dcl begin}}
{{dcl header | iterator}}
+
{{dcl header|iterator}}
{{dcl | notes={{mark custpt}} | since=c++20 | 1=
+
{{dcl|notes={{mark custpt}}|since=c++20|1=
inline namespace /*unspecified*/ {
+
inline namespace /* unspecified */ {
     inline constexpr /*unspecified*/ iter_move = /*unspecified*/;
+
     inline constexpr /* unspecified */ iter_move = /* unspecified */;
 
}
 
}
 
}}
 
}}
 
{{dcl h|Call signature}}
 
{{dcl h|Call signature}}
{{dcl|1=
+
{{dcl|since=c++20|1=
 
template< class T >
 
template< class T >
 
     requires /* see below */
 
     requires /* see below */
constexpr decltype(auto) iter_move(T&& t) noexcept(/* see below */);
+
constexpr decltype(auto) iter_move( T&& t ) noexcept(/* see below */);
 
}}
 
}}
 
{{dcl end}}
 
{{dcl end}}
Line 19: Line 19:
 
Obtains an rvalue reference or a prvalue temporary from a given iterator.
 
Obtains an rvalue reference or a prvalue temporary from a given iterator.
  
Let {{tt|t}} be an object of type {{tt|T}}, a call to {{tt|ranges::iter_move}} is expression-equivalent to:
+
A {{c|ranges::iter_move(t)}} is [[cpp/language/expressions#Expression-equivalence|expression-equivalent]] to:
# {{c|iter_move(std::forward<T>(t))}}, if {{c|std::remove_cvref_t<T>}} is a class or enumeration type and the expression is well-formed in unevaluated context, where the [[cpp/language/overload resolution|overload resolution]] is performed with the following candidates:
+
# {{c|iter_move(t)}}, if {{c|t}} has a class or enumeration type and the expression is well-formed when treated as an [[cpp/language/expressions#Potentially-evaluated expressions|unevaluated operand]], where the [[cpp/language/overload resolution|overload resolution]] of {{tt|iter_move}} is performed only with the candidates found by [[cpp/language/adl|argument-dependent lookup]].
#* {{c|void iter_move();}}
+
# Otherwise, {{c|std::move(*t)}} if {{c|*t}} is well-formed and is an lvalue.
#* any declarations of {{tt|iter_move}} found by [[cpp/language/adl|argument-dependent lookup]].
+
# Otherwise, {{c|*t}} if {{c|*t}} is well-formed and is an rvalue.
# otherwise, {{c|std::move(*std::forward<T>(t))}} if {{c|*std::forward<T>(t)}} is well-formed and is an lvalue,
+
# otherwise, {{c|*std::forward<T>(t)}} if {{c|*std::forward<T>(t)}} is well-formed and is an rvalue.
+
  
In all other cases, a call to {{tt|ranges::iter_move}} is ill-formed, which can result in [[cpp/language/sfinae|substitution failure]] when {{c|ranges::iter_move(t)}} appears in the immediate context of a template instantiation.
+
In all other cases, a call to {{tt|ranges::iter_move}} is ill-formed, which can result in [[cpp/language/sfinae|substitution failure]] when {{c|ranges::iter_move(e)}} appears in the immediate context of a template instantiation.
  
If {{c|ranges::iter_move(*std::forward<T>(t))}} is not equal to {{tt|t}}, the program is ill-formed, no diagnostic required.
+
If {{c|ranges::iter_move(e)}} is not equal to {{c|*e}}, the program is ill-formed, no diagnostic required.
  
{{cpp/expr-eq}}
 
 
{{cpp/ranges/cpo}}
 
{{cpp/ranges/cpo}}
 +
 +
===Example===
 +
{{example}}
  
 
===See also===
 
===See also===
 
{{dsc begin}}
 
{{dsc begin}}
{{dsc inc | cpp/iterator/adaptor/dsc iter_move | reverse_iterator}}
+
{{dsc inc|cpp/iterator/adaptor/dsc iter_move|reverse_iterator}}
{{dsc inc | cpp/iterator/adaptor/dsc iter_move | move_iterator}}
+
{{dsc inc|cpp/iterator/adaptor/dsc iter_move|move_iterator}}
 
{{dsc end}}
 
{{dsc end}}
  
 
{{langlinks|es|ja|zh}}
 
{{langlinks|es|ja|zh}}

Latest revision as of 23:21, 5 May 2023

 
 
Iterator library
Iterator concepts
Iterator primitives
Algorithm concepts and utilities
Indirect callable concepts
Common algorithm requirements
(C++20)
(C++20)
(C++20)
Utilities
(C++20)
Iterator adaptors
Iterator customization points
ranges::iter_move
(C++20)
Range access
(C++11)(C++14)
(C++14)(C++14)  
(C++11)(C++14)
(C++14)(C++14)  
(C++17)(C++20)
(C++17)
(C++17)
 
Defined in header <iterator>
inline namespace /* unspecified */ {

    inline constexpr /* unspecified */ iter_move = /* unspecified */;

}
(since C++20)
(customization point object)
Call signature
template< class T >

    requires /* see below */

constexpr decltype(auto) iter_move( T&& t ) noexcept(/* see below */);
(since C++20)

Obtains an rvalue reference or a prvalue temporary from a given iterator.

A ranges::iter_move(t) is expression-equivalent to:

  1. iter_move(t), if t has a class or enumeration type and the expression is well-formed when treated as an unevaluated operand, where the overload resolution of iter_move is performed only with the candidates found by argument-dependent lookup.
  2. Otherwise, std::move(*t) if *t is well-formed and is an lvalue.
  3. Otherwise, *t if *t is well-formed and is an rvalue.

In all other cases, a call to ranges::iter_move is ill-formed, which can result in substitution failure when ranges::iter_move(e) appears in the immediate context of a template instantiation.

If ranges::iter_move(e) is not equal to *e, the program is ill-formed, no diagnostic required.

Customization point objects

The name ranges::iter_move denotes a customization point object, which is a const function object of a literal semiregular class type. For exposition purposes, the cv-unqualified version of its type is denoted as __iter_move_fn.

All instances of __iter_move_fn are equal. The effects of invoking different instances of type __iter_move_fn on the same arguments are equivalent, regardless of whether the expression denoting the instance is an lvalue or rvalue, and is const-qualified or not (however, a volatile-qualified instance is not required to be invocable). Thus, ranges::iter_move can be copied freely and its copies can be used interchangeably.

Given a set of types Args..., if std::declval<Args>()... meet the requirements for arguments to ranges::iter_move above, __iter_move_fn models

Otherwise, no function call operator of __iter_move_fn participates in overload resolution.

[edit] Example

[edit] See also

(C++20)
casts the result of dereferencing the adjusted underlying iterator to its associated rvalue reference type
(function) [edit]
(C++20)
casts the result of dereferencing the underlying iterator to its associated rvalue reference type
(function) [edit]