STD::RANGES::SINGLE_VIEW(3)
π NAME π
std::ranges::single_view< _Tp > β a view that contains exactly one element. that's it. that's the whole vibe. one (1) element. iconic behaviour honestly.
β¨ SYNOPSIS β¨
first things first bestie, you gotta pull it in:
#include <ranges>
and heads up β it inherits from:
std::ranges::view_interface< single_view< _Tp > >
so all that view_interface energy comes along for free, no cap. π¦
π«Ά Public Member Functions π«Ά
okay so here's the full roster of what this baby can do, and every single one is constexpr because of course it is, she's built different:
constexpr single_view (_Tp &&__t)β constructs from an rvalue_Tp. it's markednoexcept(is_nothrow_move_constructible_v< _Tp >)so it stays chill as long as moving_Tpis chill. β¨constexpr single_view (const _Tp &__t)β the copy-ish constructor from aconst _Tp &.noexcept(is_nothrow_copy_constructible_v< _Tp >). copy energy, still valid. πtemplate<typename... _Args> constexpr single_view (in_place_t, _Args &&... __args)β the fancy one, she takes anin_place_ttag plus a pack of_Args &&... __argsand builds the element right there in place.noexcept(is_nothrow_constructible_v< _Tp, _Args... >). it's giving "I construct on my own terms". πconstexpr decltype(auto) back ()β hands you the back element. there's only one, so likeβ¦ same element, bestie. πconstexpr const _Tp * begin () const noexceptβ const iterator to the start.noexcept, obviously. βconstexpr _Tp * begin () noexceptβ non-const version ofbegin(). same deal, no const in sight. π₯constexpr auto cbegin ()β const begin, the c-flavoured one.constexpr auto cend ()β const end, matching the above.constexpr const _Tp * data () const noexceptβ const pointer to the underlying data.noexcept. π§constexpr _Tp * data () noexceptβ non-const pointer to the underlying data.noexcept. πΈconstexpr const _Tp * end () const noexceptβ const iterator past the one element.noexcept. πconstexpr _Tp * end () noexceptβ non-const version ofend().noexcept. πconstexpr decltype(auto) front ()β hands you the front element. againβ¦ it's the same single element. she's both the front AND the back. main character energy. πconstexpr operator bool ()β the truthiness conversion, and she'snoexcept(noexcept(ranges::empty(_M_derived()))). whether she's truthy depends entirely on whether the derived view is empty. the way that it just delegatesβ¦ obsessed. πconstexpr decltype(auto) operator[] (range_difference_t< _Range > __n)β index into it with an__nof typerange_difference_t< _Range >. β¨
β Static Public Member Functions β
these two are static, constexpr, and noexcept β the holy trinity of "I don't need an instance to tell you this":
static constexpr bool empty () noexceptβ is it empty?static.constexpr.noexcept. the whole package. πstatic constexpr size_t size () noexceptβ how big is it? returns asize_t. alsostatic,constexpr, andnoexcept. π
πΈ Detailed Description πΈ
okay the actual declaration, verbatim, because you deserve to see her in her full form:
template<copy_constructible _Tp>
requires is_object_v<_Tp>
class std::ranges::single_view< _Tp >
and the description, straight up:
"A view that contains exactly one element."
one element. that's the whole class. she said "I hold a single thing and I hold it FLAWLESSLY." no more, no less. periodt. π
note the requirements bestie β _Tp has to be copy_constructible, and there's a requires clause demanding is_object_v<_Tp>. so no function types, no references, no weirdness. only objects allowed. π¦
π Author π
Generated automatically by Doxygen for libstdc++ from the source code.
so like, no human author, just Doxygen doing her little automated thing. the robots ate, fr fr. π€π
okay bestie that's the whole page!! this came out of the libstdc++ manual β the page title is std::range...view< _Tp >(3) (yes the title is abbreviated like that, that's just how she's listed) and there's no date on the footer, just the libstdc++ source stamp. go forth and hold exactly one element. slay. πβ¨π
π¦ where this page comes from
- arch rolling: gcc 16.2.1+r23+gd564253eb6c8-1 Β· GPL-3.0-or-later WITH GCC-exception-3.1 AND GFDL-1.3-or-later
- fedora 44: libstdc++-docs 16.2.1-2.fc44
- fedora 44: libstdc++-docs 16.2.1-3.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms