Declaring a type as a subset of a set

对着背影说爱祢 提交于 2019-12-12 11:23:53

问题


I can easily declare a enumeration and a set.
But sometimes I want to work with only part of the enumeration and I'd like the compiler to check for me if values in the sub-enum and its subset stay within the bounds.

type
  TDay = (mon, tue, wen, thu, fri, sat, sun);
  TWeekday = (mon..fri); //not allowed;

  TDays = set of TDay;
  TWeekdays = set of TDay[mon..fri]; //not allowed

Can I declare TWeekday and TWeekdays as a derivative of TDay, if so, how?

Funny enough google does not yield anything (for me) on this issue, just plain old sets.


回答1:


You've got the wrong syntax for the subrange. Drop the brackets () and it will work.

type
  TDay = (mon, tue, wen, thu, fri, sat, sun);
  TWeekday = mon..fri; // A subrange of TDay

  TDays = set of TDay;
  TWeekdays = set of TWeekDay; 

More about Subrange Types and Sets.



来源:https://stackoverflow.com/questions/29819590/declaring-a-type-as-a-subset-of-a-set

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!