Files
core_future/tjp/core/future/FutureStrong.hpp
2026-03-06 09:28:09 -05:00

52 lines
899 B
C++
Executable File

// License: Modified MIT (NON-AI)
// See the LICENSE file in the root directory for license information.
// Copyright 2026 Timothy Prepscius
#pragma once
#include <tjp/core/exception/NullPointer.hpp>
namespace tjp {
namespace core {
template<typename U>
auto future_strong(U &&f)
{
return f.then([](auto &&g) {
using T = typename std::remove_reference<decltype(g.get())>::type;
return strong<T>(std::move(g.get()));
});
}
template<typename T, typename U>
auto future_strong(U &&f)
{
return f.then([](auto &&g) {
return strong<T>(std::move(g.get()));
});
}
template<typename U>
auto future_strong_value(U &&f)
{
return f.then([](auto &&g) {
if (auto ptr = g.get())
return *ptr;
throw exceptions::NullPointer();
});
}
template<typename U>
auto future_strong_with(U &&ptr)
{
if (ptr)
return *ptr;
throw exceptions::NullPointer();
}
} // namespace
} // namespace