Namespaces
Variants
Views
Actions

Difference between revisions of "Template:cpp/container/seq deduction guides"

From cppreference.com
m (templated iterator/allocator determination guarantee)
m (Text replace - "class_template_deduction" to "class template argument deduction")
Line 11: Line 11:
 
{{dcl end}}
 
{{dcl end}}
  
This [[cpp/language/class_template_deduction|deduction guide]] is provided for {{{1|}}} to allow deduction from an iterator range. {{cpp/enable_if|{{tt|InputIt}} satisfies {{concept|InputIterator}} and {{tt|Alloc}} satisfies {{concept|Allocator}}}}
+
This [[cpp/language/class template argument deduction|deduction guide]] is provided for {{{1|}}} to allow deduction from an iterator range. {{cpp/enable_if|{{tt|InputIt}} satisfies {{concept|InputIterator}} and {{tt|Alloc}} satisfies {{concept|Allocator}}}}
  
 
{{cpp/container/inputit_allocator_detection}}
 
{{cpp/container/inputit_allocator_detection}}

Revision as of 10:23, 3 July 2017

template< class InputIt,

          class Alloc = std::allocator<typename std::iterator_traits<InputIt>::value_type>>
(InputIt, InputIt, Alloc = Alloc())

  -> <typename std::iterator_traits<InputIt>::value_type, Alloc>;
(since C++17)

This deduction guide is provided for to allow deduction from an iterator range. This overload participates in overload resolution only if InputIt satisfies Template:concept and Alloc satisfies Template:concept

Note: the extent to which the library determines that a type does not satisfy LegacyInputIterator is unspecified, except that as a minimum integral types do not qualify as input iterators. Likewise, the extent to which it determines that a type does not satisfy Allocator is unspecified, except that as a minimum the member type Alloc::value_type must exist and the expression std::declval<Alloc&>().allocate(std::size_t{}) must be well-formed when treated as an unevaluated operand.

Example

#include <{{{1}}}>
#include <vector>
int main() {
   std::vector<int> v = {1, 2, 3, 4};
   std:: x{v.begin(), v.end()}; // uses explicit deduction guide
}