delem< t,n>源自Belem< t>和dcontainer< delem< t,n>>源自bcontainer< belem< t>>如何编码?
这个问题很容易在代码中解释。
我已经编码了几个模板类,它们是从唯一的模板类中得出的:
template<typename T,unsigned N>
struct DElem :
public BElem<T>
{};
我的问题是在我必须从基类的容器中编码这些前派生类型的容器时出现的:
template<typename T, unsigned N>
struct DContainer<DElem<T,N>> :
public BContainer<BElem<T>>
{};
在我的具体情况下,可以是std :: tuple容器或std ::数组。
我的第一个近似值是:
template<typename T, T B, std::size_t N>
struct DContainer :
public std::array<BElem<T>,N>
{
// This container is to hold **DElem<T,B>**
//
// This class has to do a cast for every
//
// **DElem<T,B>** (that is what the DContainer holds)
//
// to **BElem\<T\>**
//
// *If this task is easy I don't found the way*
};
有人有一个想法更简单地完成这些任务还是更适合其他设计?
The question is easy to explain in code.
I have coded several template classes that they derive from a unique template class:
template<typename T,unsigned N>
struct DElem :
public BElem<T>
{};
My problem arises when I have to code a container of these anterior derived types from a container of the base class:
template<typename T, unsigned N>
struct DContainer<DElem<T,N>> :
public BContainer<BElem<T>>
{};
In my concrete case, Container could be std::tuple or std::array.
My first approximation is:
template<typename T, T B, std::size_t N>
struct DContainer :
public std::array<BElem<T>,N>
{
// This container is to hold **DElem<T,B>**
//
// This class has to do a cast for every
//
// **DElem<T,B>** (that is what the DContainer holds)
//
// to **BElem\<T\>**
//
// *If this task is easy I don't found the way*
};
Someone has an idea to do these tasks more easy or some other design more appropiate?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不幸。
的A 容器 delem&lt; t,n&gt;
无法代替belem&lt; t&gt;
的容器。如果可以的话,将允许以下废话。您可以拥有的是
belem&lt; t&gt;
的 view您可能要隐藏(或
delete
)belem&lt的分配操作员; t&gt;
,因为多态性分配也相当荒谬。现在,您拥有所有
dcontainer&lt; t,n&gt;
s的共享基类,而不允许胡说八道。另外,如果您不需要 Runtime 多态性,则可以为
bcontainer
定义概念
。使用pre-concept clastica 要求href =“ https://stackoverflow.com/a/60450396/2610810”>作为基础:You are out of luck. A container of
DElem<T, N>
is not substitutable for a container ofBElem<T>
. If it could, the following nonsense would be allowed.What you can have is a view of
BElem<T>
You probably want to hide (or
delete
) the assignment operator ofBElem<T>
, because polymorphic assignment is also fairly nonsensical.Now you have a shared base class for all your
DContainer<T, N>
s which doesn't permit nonsense.Alternatively, if you don't need runtime polymorphism, you can just define a
concept
forBContainer
. Using the pre-concept Container requirements as a base: