Ada subtype equivalent in C++

前端 未结 5 2082
悲&欢浪女
悲&欢浪女 2021-02-12 22:39

Does C++ offer something similar to Ada\'s subtype to narrow a type?

E.g.:

type Weekday is (Monday, Tuesday, Wednesday, Thursday, Friday,          


        
5条回答
  •  隐瞒了意图╮
    2021-02-12 23:09

    Probably you can overload the assignation with a postcondition

    Ensures(result > 0 && result < 10);  
    

    Purely theoretical. Have not tried myself. But what do you guys think?

    But is funny to appreciate how every upgrade on C++ they push as advanced features all the stuff Ada programmers take for granted.

提交回复
热议问题