shared_ptr.hpp: implement make_single_value(), make_shared_value()

A function that constructs single_ptr from its argument.
Type can be deduced from the argument (unlike make_single).
This commit is contained in:
Nekotekina 2021-04-24 14:29:43 +03:00
parent e34c956196
commit b704cc8375
2 changed files with 17 additions and 3 deletions

View File

@ -786,12 +786,12 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool
return game_boot_result::no_errors; return game_boot_result::no_errors;
} }
// Check if path is inside the specified directory // Check if path is inside the specified directory
auto is_path_inside_path = [this](std::string_view path, std::string_view dir) auto is_path_inside_path = [this](std::string_view path, std::string_view dir)
{ {
return (GetCallbacks().resolve_path(path) + '/').starts_with(GetCallbacks().resolve_path(dir) + '/'); return (GetCallbacks().resolve_path(path) + '/').starts_with(GetCallbacks().resolve_path(dir) + '/');
}; };
// Detect boot location // Detect boot location
constexpr usz game_dir_size = 8; // size of PS3_GAME and PS3_GMXX constexpr usz game_dir_size = 8; // size of PS3_GAME and PS3_GMXX
const std::string hdd0_game = vfs::get("/dev_hdd0/game/"); const std::string hdd0_game = vfs::get("/dev_hdd0/game/");
@ -1222,7 +1222,7 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool
sys_log.notice("Elf path: %s", argv[0]); sys_log.notice("Elf path: %s", argv[0]);
} }
if (!argv[0].starts_with("/dev_hdd0/game"sv) && m_cat == "HG"sv) if (!argv[0].starts_with("/dev_hdd0/game"sv) && m_cat == "HG"sv)
{ {
sys_log.error("Booting HG category outside of HDD0!"); sys_log.error("Booting HG category outside of HDD0!");

View File

@ -388,6 +388,12 @@ namespace stx
return single_ptr<T>(*ptr, std::launder(arr)); return single_ptr<T>(*ptr, std::launder(arr));
} }
template <typename T>
static single_ptr<std::remove_reference_t<T>> make_single_value(T&& value)
{
return make_single<std::remove_reference_t<T>>(std::forward<T>(value));
}
#ifndef _MSC_VER #ifndef _MSC_VER
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#endif #endif
@ -659,6 +665,12 @@ namespace stx
return make_single<T, Init>(count); return make_single<T, Init>(count);
} }
template <typename T>
static shared_ptr<std::remove_reference_t<T>> make_shared_value(T&& value)
{
return make_single_value(std::forward<T>(value));
}
// Atomic simplified shared pointer // Atomic simplified shared pointer
template <typename T> template <typename T>
class atomic_ptr class atomic_ptr
@ -1263,3 +1275,5 @@ using stx::single_ptr;
using stx::shared_ptr; using stx::shared_ptr;
using stx::atomic_ptr; using stx::atomic_ptr;
using stx::make_single; using stx::make_single;
using stx::make_single_value;
using stx::make_shared_value;