deductiongu...rstd::vector(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’– NAME πŸ’–

okay bestie, welcome to the manpage for deductiongu...rstd::vector(3) from the C++ Standard Libary (yes, that spelling is in the header and we respect the typo πŸ’…βœ¨).

  • deductionguidesforstd::vector β€” deductionguidesforstd::vector

✨ Synopsis ✨

          Defined in header <vector>
          template< class InputIt,

                    class Alloc = std::allocator<
                        typename std::iterator_traits<InputIt>::value_type>
          >
       (1) (since C++17)
          vector( InputIt, InputIt, Alloc = Alloc() )

              -> vector<typename std::iterator_traits<InputIt>::value_type,
          Alloc>;
          template< ranges::input_range R,

                    class Alloc = std::allocator<ranges::range_value_t<R>> >
       (2) (since C++23)
          vector( std::from_range_t, R&&, Alloc = Alloc() )

              -> vector<ranges::range_value_t<R>, Alloc>;
  1. This deduction guide is provided for vector to allow deduction from an iterator range. This overload participates in overload resolution only if InputIt satisfies LegacyInputIterator and Alloc satisfies Allocator. 🫢
  2. This deduction guide is provided for vector to allow deduction from a std::from_range_t tag and an input_range. ✨
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. πŸ˜­πŸ’–

🌸 Notes 🌸

feature-test macro moment iykyk:

  • __cpp_lib_containers_ranges β€” Value: 202202L; Std: (C++23); Feature: Ranges-aware construction and insertion; overload (2) πŸ’…

πŸ¦‹ 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 effect
            std::vector y{v.begin(), v.end()};
        }

mwah πŸ’‹ this page is stamped with source/version http://cppreference.com and date 2024.06.10 β€” periodt. πŸŽ€

πŸ“¦ where this page comes from