Skip to content

Commit

Permalink
Merge pull request #86 from ikbuibui/is_specialization_of_v
Browse files Browse the repository at this point in the history
define and use is_specialization_of_v
  • Loading branch information
ikbuibui authored Jul 29, 2024
2 parents 00a80e4 + 67f02e1 commit 4bd68d3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion redGrapes/resource/fieldresource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ namespace redGrapes

template<typename... Args>
requires(
!(traits::is_specialization_of<std::decay_t<traits::first_type_t<Args...>>, FieldResource>::value
!(traits::is_specialization_of_v<std::decay_t<traits::first_type_t<Args...>>, FieldResource>
|| std::is_same_v<std::decay_t<traits::first_type_t<Args...>>, Container*>) )

FieldResource(Args&&... args)
Expand Down
25 changes: 11 additions & 14 deletions redGrapes/resource/ioresource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,24 @@ namespace redGrapes

protected:
ReadGuard(ResourceId id, std::shared_ptr<T> const& obj)
: SharedResourceObject<T, access::IOAccess>(id, obj)
: SharedResourceObject<T, access::IOAccess>(id, obj)
{
}

template<typename... Args>
ReadGuard(ResourceId id, Args&&... args)
: SharedResourceObject<T, access::IOAccess>(id, std::forward<Args>(args)...)
: SharedResourceObject<T, access::IOAccess>(id, std::forward<Args>(args)...)
{
}

ReadGuard(Resource< access::IOAccess> const& res, std::shared_ptr<T> const& obj)
: SharedResourceObject<T, access::IOAccess>(res, obj)
ReadGuard(Resource<access::IOAccess> const& res, std::shared_ptr<T> const& obj)
: SharedResourceObject<T, access::IOAccess>(res, obj)
{
}

template<typename... Args>
ReadGuard(Resource< access::IOAccess> const& res, Args&&... args)
: SharedResourceObject<T, access::IOAccess>(res, std::forward<Args>(args)...)
ReadGuard(Resource<access::IOAccess> const& res, Args&&... args)
: SharedResourceObject<T, access::IOAccess>(res, std::forward<Args>(args)...)
{
}
};
Expand Down Expand Up @@ -115,13 +115,12 @@ namespace redGrapes
{
}

WriteGuard(Resource< access::IOAccess> const& res, std::shared_ptr<T> const& obj)
: ReadGuard<T>(res, obj)
WriteGuard(Resource<access::IOAccess> const& res, std::shared_ptr<T> const& obj) : ReadGuard<T>(res, obj)
{
}

template<typename... Args>
WriteGuard(Resource< access::IOAccess> const& res, Args&&... args)
WriteGuard(Resource<access::IOAccess> const& res, Args&&... args)
: ReadGuard<T>(res, std::forward<Args>(args)...)
{
}
Expand All @@ -132,23 +131,21 @@ namespace redGrapes
template<typename T>
struct IOResource : public ioresource::WriteGuard<T>
{
IOResource(std::shared_ptr<T> const& o)
: ioresource::WriteGuard<T>(TaskFreeCtx::create_resource_uid(), o)
IOResource(std::shared_ptr<T> const& o) : ioresource::WriteGuard<T>(TaskFreeCtx::create_resource_uid(), o)
{
}

template<typename... Args>
requires(
!(traits::is_specialization_of<std::decay_t<traits::first_type_t<Args...>>, IOResource>::value
!(traits::is_specialization_of_v<std::decay_t<traits::first_type_t<Args...>>, IOResource>
|| std::is_same_v<std::decay_t<traits::first_type_t<Args...>>, std::shared_ptr<T>>) )
IOResource(Args&&... args)
: ioresource::WriteGuard<T>(TaskFreeCtx::create_resource_uid(), std::forward<Args>(args)...)
{
}

template<typename U>
IOResource(IOResource<U> const& res, std::shared_ptr<T> const& obj)
: ioresource::WriteGuard<T>(res, obj)
IOResource(IOResource<U> const& res, std::shared_ptr<T> const& obj) : ioresource::WriteGuard<T>(res, obj)
{
}

Expand Down
4 changes: 4 additions & 0 deletions redGrapes/util/traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ namespace redGrapes::traits
{
};

// Variable template for is_specialization_of
template<typename T, template<typename...> class Template>
inline constexpr bool is_specialization_of_v = is_specialization_of<T, Template>::value;

template<typename T = std::false_type, typename...>
struct first_type
{
Expand Down

0 comments on commit 4bd68d3

Please sign in to comment.