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

std::move_if_noexcept cppreference.com
cppreference.com

std::move_if_noexcept

cppreference.com
<tbody> </tbody> <tbody class="t-dcl-rev "> </tbody><tbody> </tbody>
template< class T > typename std::conditional< !std::is_nothrow_move_constructible<T>::value && std::is_copy_constructible<T>::value, const T&, T&& >::type move_if_noexcept(T& x) noexcept;
( C++11)
( C++14)
template< class T > constexpr typename std::conditional< !std::is_nothrow_move_constructible<T>::value && std::is_copy_constructible<T>::value, const T&, T&& >::type move_if_noexcept(T& x) noexcept;
( C++14)

std::move_if_noexcept rvalue , ( ), lvalue . .

x ,

std::move(x) x, .

, , std::vector::resize, , . , std::vector::resize , , , std::move_if_noexcept , . ( , , )

#include <iostream>
#include <utility>

struct Bad
{
    Bad() {}
    Bad(Bad&&)  //   
    {
        std::cout << "  ,  \n";
    }
    Bad(const Bad&) //    
    {
        std::cout << "  ,  \n";
    }
};

struct Good
{
    Good() {}
    Good(Good&&) noexcept //    
    {
        std::cout << "  ,   \n";
    }
    Good(const Good&) noexcept //    
    {
        std::cout << "  ,   \n";
    }
};

int main()
{
    Good g;
    Bad b;
    [[maybe_unused]] Good g2 = std::move_if_noexcept(g);
    [[maybe_unused]] Bad b2 = std::move_if_noexcept(b);
}

:

  ,   
  ,  

(C++11)

( ) []
(C++11)
rvalue
( ) []

Web Proxy Viewer  |  New URL  |  Original Page