GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::monostate(3) C++ Standard Libary std::monostate(3)

std::monostate - std::monostate


Defined in header <variant>
struct monostate { }; (since C++17)


Unit type intended for use as a well-behaved empty alternative in std::variant. In
particular, a variant of non-default-constructible types may list std::monostate as
its first alternative: this makes the variant itself default-constructible.


constructor trivial implicit default/copy/move constructor
(implicitly declared) (public member function)
destructor trivial implicit destructor
(implicitly declared) (public member function)
operator= trivial implicit copy/move assignment
(implicitly declared) (public member function)

std::operator==, !=, <, <=, >, >=, <=>(std::monostate)


constexpr bool operator==(monostate, monostate) noexcept { return (since C++17)
true; }
constexpr bool operator!=(monostate, monostate) noexcept { return
false; }


constexpr bool operator<(monostate, monostate) noexcept { return
false; }
constexpr bool operator>(monostate, monostate) noexcept { return (since C++17)
false; } (until C++20)
constexpr bool operator<=(monostate, monostate) noexcept { return
true; }


constexpr bool operator>=(monostate, monostate) noexcept { return
true; }
constexpr std::strong_ordering operator<=>(monostate, monostate)
noexcept (since C++20)
{ return std::strong_ordering::equal; }


All instances of std::monostate compare equal.


The <, <=, >, >=, and != operators are synthesized from operator<=> (since C++20)
and operator== respectively.

std::hash<std::monostate>


template <> struct std::hash<monostate>;


Specializes the std::hash algorithm for std::monostate.

// Run this code


#include <variant>
#include <iostream>
#include <cassert>


struct S
{
S(int i) : i(i) {}
int i;
};


int main() {


// Without the monostate type this declaration will fail.
// This is because S is not default-constructible.


std::variant<std::monostate, S> var;
assert(var.index() == 0);


try {
std::get<S>(var); // throws! We need to assign a value
}
catch(const std::bad_variant_access& e) {
std::cout << e.what() << '\n';
}


var = 12;


std::cout << std::get<S>(var).i << '\n';
}


std::get: wrong index for variant
12


constructor constructs the variant object
(public member function)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.