/* * Copyright 2015-present ScyllaDB */ /* * SPDX-License-Identifier: AGPL-3.0-or-later */ #include #include #include #include "seastarx.hh" #pragma once // // Utility for adapting types which are not nothrow move constructible into such // by wrapping them if necessary. // // Example usage: // // T val{}; // using traits = noexcept_movable; // auto f = make_ready_future(traits::wrap(std::move(val))); // T val2 = traits::unwrap(f.get()); // template struct noexcept_movable; template requires std::is_nothrow_move_constructible_v struct noexcept_movable { using type = T; static type wrap(T&& v) { return std::move(v); } static future wrap(future&& v) { return std::move(v); } static T unwrap(type&& v) { return std::move(v); } static future unwrap(future&& v) { return std::move(v); } }; template requires (!std::is_nothrow_move_constructible_v) struct noexcept_movable { using type = std::unique_ptr; static type wrap(T&& v) { return std::make_unique(std::move(v)); } static T unwrap(type&& v) { return std::move(*v); } }; template using noexcept_movable_t = typename noexcept_movable::type;