整齐地链接依赖性元组参考
给定以下类结构,我们拥有许多不同类c#
,每个类别都带有唯一数据,这些数据被传递到许多分类帐l< c#>
以及拥有许多类s#
,每个类都取决于c#
下的类的某些子集,我已经建立了一个元组,该元组包含Manager类中的所有分类帐e e e
。
// Dependency classes
struct C {};
struct C1 : C {};
struct C2 : C {};
// Dependency data ledger
template <class T>
class L {};
// Dependency user
template <class... Cs>
struct S {
using Deps = std::tuple<Cs...>;
using DepRefs = std::tuple<L<Cs>&...>;
};
struct S1 : S<C1> {};
struct S2 : S<C1, C2> {};
// Manager
template <class... Ss>
class E;
template <class... Ss>
class E : public E<all_deps_no_duplicates<Ss...>, Ss...> {};
template <class... Cs, class... Ss>
class E<std::tuple<Cs...>, Ss...> {
std::tuple<L<Cs>...> DepsData;
std::tuple<typename Ss::DepsRefs...> DepsRefs; // Problem instantiation.
};
// Usage
int main() { E<S1, S2> e; };
然后存在哪些优雅的解决方案来建立一个次要元组,其中包含对每个依赖项用户的依赖性分类帐中的每一个的引用?依赖分类帐的元组中没有重复的,每个依赖性一个分类帐,每个依赖性用户也许。例如,在给出的代码中,我希望Manager类中的第一个和第二个元组e
分别包含:
depSdata:
std::tuple<
L<C1>(), // 1st element: a ledger for C1
L<C2>() // 2nd element: a ledger for C2
>
depSrefs:
std::tuple<
std::tuple<L<C1>&>, // tuple containing reference to DepsData 1st element
std::tuple<L<C1>&, L<C2>&> // tuple containing reference to DepsData 1st and 2nd elements
>
使用l&lt; c1&gt;&amp;
在depsrefs
中引用,请参考depsdata
中指定的相同分类帐。
Given the following class structure in which we possess a number of different classes C#
, each with unique data that is passed into a number of ledgers L<C#>
, as well as possessing a number of classes S#
, each depending on some subset of the classes under the C#
, I have established a tuple containing all ledgers in the manager class E
.
// Dependency classes
struct C {};
struct C1 : C {};
struct C2 : C {};
// Dependency data ledger
template <class T>
class L {};
// Dependency user
template <class... Cs>
struct S {
using Deps = std::tuple<Cs...>;
using DepRefs = std::tuple<L<Cs>&...>;
};
struct S1 : S<C1> {};
struct S2 : S<C1, C2> {};
// Manager
template <class... Ss>
class E;
template <class... Ss>
class E : public E<all_deps_no_duplicates<Ss...>, Ss...> {};
template <class... Cs, class... Ss>
class E<std::tuple<Cs...>, Ss...> {
std::tuple<L<Cs>...> DepsData;
std::tuple<typename Ss::DepsRefs...> DepsRefs; // Problem instantiation.
};
// Usage
int main() { E<S1, S2> e; };
What elegant solutions exist then to establish a secondary tuple containing references to each one of each dependency user's dependency ledgers? There are no duplicates in the tuple of dependency ledgers with one ledger per dependency with perhaps many dependency users each. For example, in the code given, I would want the first and second tuples in the manager class E
to respectively contain:
DepsData:
std::tuple<
L<C1>(), // 1st element: a ledger for C1
L<C2>() // 2nd element: a ledger for C2
>
DepsRefs:
std::tuple<
std::tuple<L<C1>&>, // tuple containing reference to DepsData 1st element
std::tuple<L<C1>&, L<C2>&> // tuple containing reference to DepsData 1st and 2nd elements
>
With both L<C1>&
references in DepsRefs
referring to the same ledger specified in DepsData
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,专注于参考初始化,您可能会执行以下操作:
demo
So focusing on the reference initialization, you might do something like:
Demo