Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      deduction guides forstd::stack

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

      [edit template]
       
       
       
       
      Defined in header<stack>
      template<class Container>

      stack( Container)

         -> stack<typename Container::value_type, Container>;
      (1)(since C++17)
      template<class Container,class Alloc>

      stack( Container, Alloc)

         -> stack<typename Container::value_type, Container>;
      (2)(since C++17)
      template<class InputIt>

      stack( InputIt, InputIt)

         -> stack<typenamestd::iterator_traits<InputIt>::value_type>;
      (3)(since C++23)
      template<class InputIt,class Alloc>

      stack( InputIt, InputIt, Alloc)
         -> stack<typenamestd::iterator_traits<InputIt>::value_type,

             std::deque<typenamestd::iterator_traits<InputIt>::value_type, Alloc>>;
      (4)(since C++23)
      template<ranges::input_range R>

      stack(std::from_range_t, R&&)

         -> stack<ranges::range_value_t<R>>;
      (5)(since C++23)
      template<ranges::input_range R,class Allocator>

      stack(std::from_range_t, R&&, Allocator)
         -> stack<ranges::range_value_t<R>,

             std::deque<ranges::range_value_t<R>, Allocator>>;
      (6)(since C++23)

      Thesededuction guides are provided forstack to allow deduction from underlying container type.

      1) Deduces underlying container type from the argument.
      2) Same as(1), except that the allocator is provided.
      3) Deduces the element type from the iterator, usingstd::deque<typenamestd::iterator_traits<InputIt>::value_type> as the underlying container type.
      4) Same as(3), except that the allocator is provided.
      5) Deduces the element type from astd::from_range_t tag and aninput_range.
      6) Same as(5), except that the allocator is provided.

      These overloads participate in overload resolution only if

      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_adaptor_iterator_pair_constructor202106L(C++23)Iterator pair constructors forstd::queue andstd::stack; overloads(2) and(4)
      __cpp_lib_containers_ranges202202L(C++23)Ranges-aware construction and insertion; overloads(5) and(6)

      [edit]Example

      Run this code
      #include <stack>#include <vector> int main(){std::vector<int> v={1,2,3,4};std::stack s{v};// guide #1 deduces std::stack<int, vector<int>>}
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/container/stack/deduction_guides&oldid=129992"

      [8]ページ先頭

      ©2009-2025 Movatter.jp