deductiongu...string_view(3)
π NAME π
deductionguidesforstd::basic_string_view β deductionguidesforstd::basic_string_view
Okay so this is deductiongu...string_view(3) from the C++ Standard Libary manual β yes, βLibaryβ with the typo is literally what the header says, iykyk π
. The NAME line is the same thing twice, and we are keeping it that way, periodt.
β¨ Synopsis β¨
Defined in header <string_view>.
template< class It, class End >
basic_string_view( It, End ) ->
(1) (since C++20)
basic_string_view<std::iter_value_t<It>>;
template< class R >
basic_string_view( R&& ) ->
(2) (since C++23)
basic_string_view<ranges::range_value_t<R>>;
These deduction guides are provided for std::basic_string_view, bestie. Hereβs the tea:
- Guide
(1), since C++20 β this deduction guide allows the character type to be deduced from the iterator-sentinel pair. This overload participates in overload resolution only ifItsatisfiescontiguous_iteratorandEndsatisfiessized_sentinel_forforIt. - Guide
(2), since C++23 β this deduction guide allows the character type to be deduced from the range. This overload participates in overload resolution only ifRsatisfiescontiguous_range.
π Example π
The example literally tells you // Run this code, so run it, bestie:
// Run this code
#include <array>
#include <iostream>
#include <string_view>
int main()
{
std::array a1{'n', 'u', 'c', 'l', 'e', 'o', 'n', 's', ':', '\n'};
std::basic_string_view s1(a1.cbegin(), a1.cend()); // deduction: CharT -> char
static_assert(std::is_same_v<decltype(s1)::value_type, char>);
std::cout << s1;
std::array a2{L'p', L'r', L'o', L't', L'o', L'n', L's', L'\n'};
std::basic_string_view s2(a2.cbegin(), a2.cend()); // deduction: CharT -> wchar_t
static_assert(std::is_same_v<decltype(s2)::value_type, wchar_t>);
std::wcout << s2;
std::array<long, 9> a3{'n', 'e', 'u', 't', 'r', 'o', 'n', 's', '\n'};
std::basic_string_view s3(a3.cbegin(), a3.cend()); // deduction: CharT -> long
static_assert(std::is_same_v<decltype(s3)::value_type, long>);
for (const auto e : s3)
std::cout << static_cast<char>(e);
}
π Output π
nucleons:
protons
neutrons
Cute sign-off π: source/version is http://cppreference.com, date is 2024.06.10, and the footer tag is deductiongu...string_view(3). Love that for us, bye π
β¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms