std::experi...::operator*(3)
π std::experimental::optional::operator->, std::experimental::optional::operator* π
okay so we're in the C++ Standard Library manual, bestie, and this page is about std::experimental::optional's operator-> and operator*. two lil access operators, one big vibe. π
β¨ NAME β¨
std::experimental::optional::operator->, std::experimental::optional::operator* β yes bestie, both of them, the arrow one and the star one. no cap, this page covers the whole duo. π¦
π Synopsis π
here's the overload family exactly as the page lays it out, library fundamentals TS and all:
constexpr const T* operator->() const; (1) (library fundamentals
TS)
constexpr T* operator->(); (1) (library fundamentals
TS)
constexpr const T& operator*() const&; (2) (library fundamentals
TS)
constexpr T& operator*() &; (2) (library fundamentals
TS)
constexpr const T&& operator*() const&&; (2) (library fundamentals
TS)
constexpr T&& operator*() &&; (2) (library fundamentals
TS)
both of these access the contained value, periodt. π₯
- returns a pointer to the contained value.
- returns a reference to the contained value.
β οΈ The behavior is undefined if *this does not contain a value. like, genuinely undefined, bestie. not a cute little vibe check. do not test it. π
π Parameters π
none. zero. (none). it's giving "no thoughts, just access." π
πΈ Return value πΈ
a pointer or reference to the contained value. that's the whole return-value tea. π΅
π¦ Exceptions π¦
throws nothing. not even one tiny exception. literally nothing. slay. β¨
π Notes π
this operator does not check whether the optional contains a value. no vibe check, no safety net, nothing. if checked access is needed, value() or value_or() may be used. iykyk. π
π§ Example π§
// Run this code
#include <experimental/optional>
#include <iostream>
#include <string>
using namespace std::literals;
int main()
{
std::experimental::optional<int> opt1 = 1;
std::cout << *opt1 << '\n';
std::experimental::optional<std::string> opt2 = "abc"s;
std::cout << opt2->size() << '\n';
}
π¨οΈ Output
1
3
ate. no crumbs. π
π See also π
valueβ returns the contained value (public member function)value_orβ returns the contained value if available, another value otherwise (public member function)
π·οΈ Category π·οΈ
* Noindexed pages
shoutout to http://cppreference.com, version 2024.06.10, and the page std::experi...::operator*(3) β that's the footer, bestie, mwah ππ
π¦ 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