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::variant::~variant(3) C++ Standard Libary std::variant::~variant(3)

std::variant::~variant - std::variant::~variant


~variant(); (since C++17)
(until C++20)
constexpr ~variant(); (since C++20)


If valueless_by_exception() is true, does nothing. Otherwise, destroys the currently
contained value.


This destructor is trivial if std::is_trivially_destructible_v<T_i> is true for all
T_i in Types....

// Run this code


#include <variant>
#include <cstdio>


int main()
{
struct X { ~X() { puts("X::~X();"); } };
struct Y { ~Y() { puts("Y::~Y();"); } };


{
puts("entering block #1");
std::variant<X,Y> var;
puts("leaving block #1");
}


{
puts("entering block #2");
std::variant<X,Y> var{ std::in_place_index_t<1>{} }; // constructs var(Y)
puts("leaving block #2");
}
}


entering block #1
leaving block #1
X::~X();
entering block #2
leaving block #2
Y::~Y();


Defect reports


The following behavior-changing defect reports were applied retroactively to
previously published C++ standards.


DR Applied to Behavior as published Correct behavior
the destructor was not constexpr while
P2231R1 C++20 non-trivial destructors can be constexpr in made constexpr
C++20

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.