Skip to content

Commit 895d613

Browse files
committed
refactor(reflection)
1 parent 088a63b commit 895d613

File tree

9 files changed

+30
-74
lines changed

9 files changed

+30
-74
lines changed

include/concurrent_object.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
// Created by BlurringShadow at 2021-03-12-下午 1:56
1+
// Created by BlurringShadow at 2021-03-12-下午 1:56
22

33
#pragma once
44

55
#include <shared_mutex>
6-
#include <mutex>
76

87
#include "reflection/reflection.h"
98
#include "functional/operations.h"
@@ -25,7 +24,7 @@ namespace stdsharp
2524
constexpr auto& raw() noexcept { return object_; }
2625

2726
template<auto Name>
28-
requires(std::ranges::equal(Name, "raw"_ltr))
27+
requires(Name == "raw"sv)
2928
constexpr auto operator()(const reflection::member_t<Name>) noexcept
3029
{
3130
return [this]() { return this->raw(); };
@@ -34,7 +33,7 @@ namespace stdsharp
3433
constexpr auto& raw() const noexcept { return object_; }
3534

3635
template<auto Name>
37-
requires(std::ranges::equal(Name, "raw"_ltr))
36+
requires(Name == "raw"sv)
3837
constexpr auto operator()(const reflection::member_t<Name>) const noexcept
3938
{
4039
return [this]() { return this->raw(); };
@@ -48,7 +47,7 @@ namespace stdsharp
4847
}
4948

5049
template<auto Name>
51-
requires(std::ranges::equal(Name, "read"_ltr))
50+
requires(Name == "read"sv)
5251
constexpr auto operator()(const reflection::member_t<Name>) const noexcept
5352
{
5453
return [this]() { return this->read(); };
@@ -62,7 +61,7 @@ namespace stdsharp
6261
}
6362

6463
template<auto Name>
65-
requires(std::ranges::equal(Name, "write"_ltr))
64+
requires(Name == "write"sv)
6665
constexpr auto operator()(const reflection::member_t<Name>) noexcept
6766
{
6867
return [this]() { return this->write(); };

include/reflection/reflection.h

Lines changed: 18 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -14,58 +14,19 @@ namespace stdsharp::reflection
1414

1515
namespace details
1616
{
17-
template<::std::convertible_to<::std::string_view> auto Literal>
18-
struct member_t
19-
{
20-
static constexpr ::std::string_view name = Literal;
21-
};
22-
2317
template<typename>
2418
struct is_std_pair;
2519

2620
template<typename T, typename U>
2721
struct is_std_pair<::std::pair<T, U>>
2822
{
2923
};
30-
31-
template<auto Literal>
32-
struct data_member_t : details::member_t<Literal>
33-
{
34-
template<typename T>
35-
requires requires
36-
{
37-
requires static_cast<::std::string_view>(Literal) == "first";
38-
is_std_pair<::std::remove_cvref_t<T>>{};
39-
}
40-
constexpr auto& operator()(T&& p) const noexcept { return ::std::forward<T>(p).first; }
41-
42-
template<typename T>
43-
requires requires
44-
{
45-
requires static_cast<::std::string_view>(Literal) == "second";
46-
is_std_pair<::std::remove_cvref_t<T>>{};
47-
}
48-
constexpr auto& operator()(T&& p) const noexcept { return ::std::forward<T>(p).second; }
49-
};
50-
51-
template<auto Literal>
52-
struct member_function_t : details::member_t<Literal>
53-
{
54-
};
5524
}
5625

57-
template<auto Literal>
26+
template<::std::convertible_to<::std::string_view> auto Literal>
5827
struct member_t
5928
{
60-
template<typename... Args>
61-
requires(
62-
::std::invocable<details::member_t<Literal>, Args...> &&
63-
!functional::cpo_invocable<member_t<Literal>, Args...>)
64-
constexpr decltype(auto) operator()(Args&&... args) const
65-
noexcept(concepts::nothrow_invocable<details::member_t<Literal>, Args...>)
66-
{
67-
return details::member_t<Literal>{}(::std::forward<Args>(args)...);
68-
}
29+
static constexpr ::std::string_view name = Literal;
6930

7031
template<typename... Args>
7132
requires functional::cpo_invocable<member_t<Literal>, Args...>
@@ -80,20 +41,26 @@ namespace stdsharp::reflection
8041
inline constexpr member_t<Literal> member{};
8142

8243
template<auto Literal>
83-
struct data_member_t
44+
struct data_member_t : member_t<Literal>
8445
{
8546
// NOLINTNEXTLINE(hicpp-explicit-conversions)
8647
constexpr data_member_t(const member_t<Literal> = {}) noexcept {}
8748

88-
template<typename... Args>
89-
requires(
90-
::std::invocable<details::data_member_t<Literal>, Args...> &&
91-
!functional::cpo_invocable<data_member_t<Literal>, Args...>)
92-
constexpr decltype(auto) operator()(Args&&... args) const
93-
noexcept(concepts::nothrow_invocable<details::data_member_t<Literal>, Args...>)
94-
{
95-
return details::data_member_t<Literal>{}(::std::forward<Args>(args)...);
96-
}
49+
template<typename T>
50+
requires requires
51+
{
52+
requires static_cast<::std::string_view>(Literal) == "first";
53+
details::is_std_pair<::std::remove_cvref_t<T>>{};
54+
}
55+
constexpr auto& operator()(T&& p) const noexcept { return ::std::forward<T>(p).first; }
56+
57+
template<typename T>
58+
requires requires
59+
{
60+
requires static_cast<::std::string_view>(Literal) == "second";
61+
details::is_std_pair<::std::remove_cvref_t<T>>{};
62+
}
63+
constexpr auto& operator()(T&& p) const noexcept { return ::std::forward<T>(p).second; }
9764

9865
template<typename... Args>
9966
requires functional::cpo_invocable<data_member_t<Literal>, Args...>
@@ -113,16 +80,6 @@ namespace stdsharp::reflection
11380
// NOLINTNEXTLINE(hicpp-explicit-conversions)
11481
constexpr member_function_t(const member_t<Literal> = {}) noexcept {}
11582

116-
template<typename... Args>
117-
requires(
118-
::std::invocable<details::member_function_t<Literal>, Args...> &&
119-
!functional::cpo_invocable<member_function_t<Literal>, Args...>)
120-
constexpr decltype(auto) operator()(Args&&... args) const
121-
noexcept(concepts::nothrow_invocable<details::member_function_t<Literal>, Args...>)
122-
{
123-
return details::member_function_t<Literal>{}(::std::forward<Args>(args)...);
124-
}
125-
12683
template<typename... Args>
12784
requires functional::cpo_invocable<member_function_t<Literal>, Args...>
12885
constexpr decltype(auto) operator()(Args&&... args) const

include/type_traits/function.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Created by BlurringShadow at 2021-03-03-下午 4:33
1+
// Created by BlurringShadow at 2021-03-03-下午 4:33
22

33
#pragma once
44
#include "type_sequence.h"

include/type_traits/member.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Created by BlurringShadow at 2021-03-05-下午 11:53
1+
// Created by BlurringShadow at 2021-03-05-下午 11:53
22

33
#pragma once
44

include/type_traits/object.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Created by BlurringShadow at 2021-03-05-下午 11:53
1+
// Created by BlurringShadow at 2021-03-05-下午 11:53
22

33
#pragma once
44

include/type_traits/type_sequence.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Created by BlurringShadow at 2021-03-03-下午 4:35
1+
// Created by BlurringShadow at 2021-03-03-下午 4:35
22

33
#pragma once
44

include/type_traits/type_traits.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#pragma once
1+
#pragma once
22

33
#include "type_traits/member.h"
44
#include "type_traits/object.h"

include/type_traits/value_sequence.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Created by BlurringShadow at 2021-03-04-下午 11:27
1+
// Created by BlurringShadow at 2021-03-04-下午 11:27
22

33
#pragma once
44

include/utility/utility.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Created by BlurringShadow at 2021-02-27-下午 10:24
1+
// Created by BlurringShadow at 2021-02-27-下午 10:24
22

33
#pragma once
44

0 commit comments

Comments
 (0)