perf: 加强读取资源类的约束,增加单例 concept

This commit is contained in:
MistEO
2022-09-04 00:59:01 +08:00
parent 7c8bf92eb4
commit 3f4e588e83
3 changed files with 5 additions and 3 deletions

View File

@@ -7,7 +7,6 @@
#include <thread>
#include <type_traits>
#include <utility>
#include <vector>
#include "AsstRanges.hpp"
#include "AsstUtils.hpp"

View File

@@ -19,7 +19,7 @@ namespace asst
private:
template <typename T>
requires std::is_base_of_v<AbstractResource, T>
requires std::is_base_of_v<AbstractResource, T> && Singleton<T>
bool load_resource(const std::filesystem::path& path)
{
if (!std::filesystem::exists(path)) {
@@ -29,7 +29,7 @@ namespace asst
}
template <typename T>
requires std::is_base_of_v<AbstractConfigerWithTempl, T>
requires std::is_base_of_v<AbstractConfigerWithTempl, T> && Singleton<T>
bool load_resource_with_templ(const std::filesystem::path& path, const std::filesystem::path& templ_dir)
{
if (!load_resource<T>(path)) {

View File

@@ -23,4 +23,7 @@ namespace asst
protected:
SingletonHolder() = default;
};
template <typename T>
concept Singleton = std::is_base_of_v<SingletonHolder<T>, T>;
}