STD::RANGES::SINGLE_VIEW(3)

πŸ“¦
version 16.2.1+r23+gd564253eb6c8 Β· 6 versions
, in arch rolling, fedora 44

πŸ’– 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 marked noexcept(is_nothrow_move_constructible_v< _Tp >) so it stays chill as long as moving _Tp is chill. ✨
  • constexpr single_view (const _Tp &__t) β€” the copy-ish constructor from a const _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 an in_place_t tag plus a pack of _Args &&... __args and 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 of begin(). 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 of end(). 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's noexcept(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 __n of type range_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 a size_t. also static, constexpr, and noexcept. 🌈

🌸 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