[ Web Proxy ]
URL:
Viewing: https://ru.cppreference.com/cpp/utility/optional/reset [Back]  [Original]

std::optional<T>::reset cppreference.com
cppreference.com

std::optional<T>::reset

cppreference.com
 
C++
(C++20)
(C++20)
(C++11)
(C++20)
/
(C++11)
(C++11)
(C++11)
(C++17)
 
 
 
<tbody> </tbody> <tbody class="t-dcl-rev "> </tbody><tbody> </tbody>
void reset() noexcept;
( C++17)
( C++20)
constexpr void reset() noexcept;
( C++20)

*this , , value().T::~T(). .

*this .

#include <optional>
#include <iostream>

struct A {
    std::string s;
    A(std::string str) : s(std::move(str))  { std::cout << " \n"; }
    ~A() { std::cout << " \n"; }
    A(const A& o) : s(o.s) { std::cout << "  \n"; }
    A(A&& o) : s(std::move(o.s)) { std::cout << "  \n"; }
    A& operator=(const A& other) {
        s = other.s;
        std::cout << "  \n";
        return *this;
    }
    A& operator=(A&& other) {
        s = std::move(other.s);
        std::cout << "  \n";
        return *this;
    }
};

int main()
{
    std::cout << "  optional:\n";
    std::optional<A> opt;

    std::cout << "   :\n";
    opt = A("Lorem ipsum dolor sit amet, consectetur adipiscing elit nec.");

    std::cout << " optional:\n";
    opt.reset();
    std::cout << " \n";
}

:

  optional:
   :
 
  
 
 optional:
 
 

C++:

WG C++20 reset constexpr,
constexpr C++20
constexpr


(public -) []

Web Proxy Viewer  |  New URL  |  Original Page