Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      deduction guides forstd::vector

      From cppreference.com
      <cpp‎ |container‎ |vector

      [edit template]
       
       
       
      std::vector
      Member types
      Member functions
      Non-member functions
      (until C++20)(until C++20)(until C++20)(until C++20)(until C++20)
      Deduction guides(C++17)
       
      Defined in header<vector>
      template<class InputIt,

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

         -> vector<typenamestd::iterator_traits<InputIt>::value_type, Alloc>;
      (1)(since C++17)
      template<ranges::input_range R,

               class Alloc=std::allocator<ranges::range_value_t<R>>>
      vector(std::from_range_t, R&&, Alloc= Alloc())

         -> vector<ranges::range_value_t<R>, Alloc>;
      (2)(since C++23)
      1) Thisdeduction guide is provided for vector to allow deduction from an iterator range. This overload participates in overload resolution only ifInputIt satisfiesLegacyInputIterator andAlloc satisfiesAllocator.
      2) This deduction guide is provided for vector to allow deduction from astd::from_range_t tag and aninput_range.

      Note: the extent to which the library determines that a type does not satisfyLegacyInputIterator 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 satisfyAllocator is unspecified, except that as a minimum the member typeAlloc::value_type must exist and the expressionstd::declval<Alloc&>().allocate(std::size_t{}) must be well-formed when treated as an unevaluated operand.

      [edit]Notes

      Feature-test macroValueStdFeature
      __cpp_lib_containers_ranges202202L(C++23)Ranges-aware construction and insertion; overload(2)

      [edit]Example

      Run this code
      #include <vector> int main(){std::vector<int> v={1,2,3,4}; // uses explicit deduction guide to deduce std::vector<int>std::vector x(v.begin(), v.end()); // deduces std::vector<std::vector<int>::iterator>// first phase of overload resolution for list-initialization selects the candidate// synthesized from the initializer-list constructor; second phase is not performed// and deduction guide has no effectstd::vector y{v.begin(), v.end()};}
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/container/vector/deduction_guides&oldid=138283"

      [8]ページ先頭

      ©2009-2025 Movatter.jp