适用于“上下文敏感”的数据结构。 3元组? [英] Suitable data structure for a "context sensitive" 3-tuple?
问题描述
我想将数据存储在3元组{a,b,c}中。
元素a是枚举,并且元素c是一个枚举,它由一个特定的(即确定的)来确定。
一个例子将有助于进一步澄清。我举两个例子,一个是
有效实例,另一个是无效实例。
typedef enum {bovine,gamebird,seafood} general_meat;
注意:上面的每个元素都是它自己的一个类别。我可以
进一步划分海鲜类别以产生以下分组:
typedef enum {扇贝,龙虾,鳕鱼,虾,鲑鱼}海鲜;
class Meal {
general_meat m;
bool cook_first;
X data_type_that_will_accept_specific_types_of_gener al_meat_m;
}
我希望上面的插图能够解决这个问题。
class Meal(显然?)必须是模板类 - 但是我
我不知道如何强制X成为一个子集(即允许的类型)
由m决定。
我期待任何有关可能解决方案的想法。谢谢
Hi,
I want to store data in a 3-tuple {a,b,c}.
Element a is an enumeration, and element c is an enumeration which is
specific (i.e. determined) by a.
An example will help clarify further. I give two examples, one of a
valid instance, and the other, an invalid instance.
typedef enum { bovine, gamebird, seafood } general_meat ;
Note: each of the elements above is a category of its own. I can
further partition the seafood category to yield the following grouping:
typedef enum { scallops, lobster, cod, prawn, salmon} seafood ;
class Meal {
general_meat m ;
bool cook_first ;
X data_type_that_will_accept_specific_types_of_gener al_meat_m ;
}
I hope the illustration above provides some illumination on the problem.
class Meal will (obviously?) have to be a template class - but I
don''t know how to enforce X to be a subset (i.e. a permissable type)
determined by m.
I look forward to any ideas for a possible solution. Thanks
推荐答案
Susan Baker写道:
Susan Baker wrote:
我想将数据存储在3元组{a,b,c}中。
元素a是枚举,元素c是枚举,它是
具体(即确定)由一个。
一个例子将有助于进一步澄清。我举两个例子,一个是有效的实例,另一个是无效的实例。
typedef enum {bovine,gamebird,seafood} general_meat;
注意:上面的每个元素都是它自己的一个类别。我可以进一步分类海鲜类别以产生以下分组:
typedef enum {扇贝,龙虾,鳕鱼,虾,鲑鱼}海鲜;
class Meal {
general_meat m;
bool cook_first;
X data_type_that_will_accept_specific_types_of_gener al_meat_m;
我希望上面的插图能够解决问题。
由m确定。
我期待任何有关可能解决方案的想法。谢谢
Hi,
I want to store data in a 3-tuple {a,b,c}.
Element a is an enumeration, and element c is an enumeration which is
specific (i.e. determined) by a.
An example will help clarify further. I give two examples, one of a
valid instance, and the other, an invalid instance.
typedef enum { bovine, gamebird, seafood } general_meat ;
Note: each of the elements above is a category of its own. I can further
partition the seafood category to yield the following grouping:
typedef enum { scallops, lobster, cod, prawn, salmon} seafood ;
class Meal {
general_meat m ;
bool cook_first ;
X data_type_that_will_accept_specific_types_of_gener al_meat_m ;
}
I hope the illustration above provides some illumination on the problem.
class Meal will (obviously?) have to be a template class - but I don''t
know how to enforce X to be a subset (i.e. a permissable type)
determined by m.
I look forward to any ideas for a possible solution. Thanks
好的。以下是我之前承诺的两个例子(对象):
meal1 {海鲜,不,扇贝} //< - 有效
meal2 {牛,是的,扇贝} //< - 无效
Ok. Here are the two examples (of objects) I promised earlier:
meal1 { seafood, no, scallops } // <- valid
meal2 { bovine, yes, scallops } //<- invalid
Susan Baker写道:
Susan Baker wrote:
我想将数据存储在3元组{a,b,c}中。
元素a是枚举,元素c是枚举,它是
具体(即确定)由a。
一个例子将有助于进一步澄清。我举两个例子,一个是有效的实例,另一个是无效的实例。
typedef enum {bovine,gamebird,seafood} general_meat;
注意:上面的每个元素都是它自己的一个类别。我可以进一步划分海鲜类别以产生以下分组:
typedef enum {扇贝,龙虾,鳕鱼,虾,鲑鱼}海鲜;
class Meal {
general_meat m;
bool cook_first;
X data_type_that_will_accept_specific_types_of_gener al_meat_m;
我希望上面的插图能够解决问题。
由m确定。 br />
我期待任何有关可能解决方案的想法。谢谢
Hi,
I want to store data in a 3-tuple {a,b,c}.
Element a is an enumeration, and element c is an enumeration which is
specific (i.e. determined) by a.
An example will help clarify further. I give two examples, one of a
valid instance, and the other, an invalid instance.
typedef enum { bovine, gamebird, seafood } general_meat ;
Note: each of the elements above is a category of its own. I can
further partition the seafood category to yield the following grouping:
typedef enum { scallops, lobster, cod, prawn, salmon} seafood ;
class Meal {
general_meat m ;
bool cook_first ;
X data_type_that_will_accept_specific_types_of_gener al_meat_m ;
}
I hope the illustration above provides some illumination on the problem.
class Meal will (obviously?) have to be a template class - but I
don''t know how to enforce X to be a subset (i.e. a permissable type)
determined by m.
I look forward to any ideas for a possible solution. Thanks
继承有什么问题?制作
data_type_that_will_accept_specific_types_of_gener al_meat_m一个指针
到general_meal。从
general_meal中获取牛,高粱和海鲜。
dan
What is wrong with inheritance? Make
data_type_that_will_accept_specific_types_of_gener al_meat_m a pointer
to a general_meal. Derive bovine, gamberid and seafood from
general_meal.
dan
Dan Cernat写道:
Dan Cernat wrote:
Susan Baker写道:
Susan Baker wrote:
我想将数据存储在3元组{a,b,c}中。
元素a是枚举,元素c是特定的枚举(即确定)a。
一个例子将有助于进一步澄清。我举两个例子,一个是有效的实例,另一个是无效的实例。
typedef enum {bovine,gamebird,seafood} general_meat;
注意:上面的每个元素都是它自己的一个类别。我可以进一步划分海鲜类别以产生以下分组:
typedef enum {扇贝,龙虾,鳕鱼,虾,鲑鱼}海鲜;
class Meal {
general_meat m;
bool cook_first;
X data_type_that_will_accept_specific_types_of_gener al_meat_m;
我希望上面的插图能够解决问题。
由m确定。 br />
我期待任何有关可能解决方案的想法。谢谢
Hi,
I want to store data in a 3-tuple {a,b,c}.
Element a is an enumeration, and element c is an enumeration which is
specific (i.e. determined) by a.
An example will help clarify further. I give two examples, one of a
valid instance, and the other, an invalid instance.
typedef enum { bovine, gamebird, seafood } general_meat ;
Note: each of the elements above is a category of its own. I can
further partition the seafood category to yield the following grouping:
typedef enum { scallops, lobster, cod, prawn, salmon} seafood ;
class Meal {
general_meat m ;
bool cook_first ;
X data_type_that_will_accept_specific_types_of_gener al_meat_m ;
}
I hope the illustration above provides some illumination on the problem.
class Meal will (obviously?) have to be a template class - but I
don''t know how to enforce X to be a subset (i.e. a permissable type)
determined by m.
I look forward to any ideas for a possible solution. Thanks
继承有什么问题?使
data_type_that_will_accept_specific_types_of_gener al_meat_m成为general_meal的指针。来自
general_meal的牛,高粱和海鲜。
dan
What is wrong with inheritance? Make
data_type_that_will_accept_specific_types_of_gener al_meat_m a pointer
to a general_meal. Derive bovine, gamberid and seafood from
general_meal.
dan
general_meal是一个新类,还是你的意思是general_meat? 。我可以看到
你继续使用遗产建议。我可以有一个
heirarchy像:
肉
|
----- --------------------
| | |
牛游戏鸟海鲜
然后分别对其中的每一个进行分类。这是一种叮叮当当的方式 - 它也意味着大量的编码 - 以及所有随之而来的问题。我想b / b
是否有办法应用泛型编程
哲学所以我可以有一个通用工厂生产每个
这些分组(牛,gamebird等)。
当使用任何这些肉派生类(它们应该是抽象的 - 因为它们是分类时)班级只能用有意义的价值来实现
,所以如果我要求海鲜餐,
我最终不会吃生猪肉(例如0。因为猪肉不是一个有效的
成员(如果你愿意的话,枚举项目)的海鲜类。我知道所有
这可以通过继承和明智的类型检查来完成
在类构造函数等中传递 - 但这并不容易
可扩展,例如,如果我决定允许新项目成为
的一部分海鲜类别,我有很多重构要做 - 我是
只是想知道是否有一种方法这是通用的方式(如果
不是全部,那么至少有一些)。
Is general_meal a new class, or did you mean general_meat ?. I can see
where you''re going with the inheritence suggestion. I could have a
heirarchy like:
meat
|
-------------------------
| | |
bovine gamebird seafood
and then sub-class each one of them accordingly. This is one way of ding
it - it also means a lot of coding - with all its attendant problems. I
was wondering if there was a way of applying generic programming
philosophy so I could have one generic factory that produces each of
these groupings (bovine, gamebird etc).
When using any of these meat derived classes (which should really be
abstract - since they are classifications), the derived class can only
instantiate with meaningful values, so that if I ask for a seafood Meal,
I do not end up with raw pork (for instance0. since pork is not a valid
member (enumeration item if you like) for the class seafood. I know all
of this can be done using inheritance and judious inspection of types
being passed in the class constructor etc - but this is not easily
extendable, for example, if I decide to allow new items to be part of
the seafood category, I have an awful lot of refactoring to do - I was
just wondering if there was a way of writing this in a generic way (if
not all, then at least some of it).
这篇关于适用于“上下文敏感”的数据结构。 3元组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!