「view this page in B3 βῆτα server」

Revisions №60956

branch: master 「№60956」
Commited by: Jack Maguire
GitHub commit link: 「e60f20795c0db6d5」 「№4237」
Difference from previous tested commit:  code diff
Commit date: 2019-10-01 08:47:08

Merge pull request #4237 from RosettaCommons/JackMaguire/StrongTypeAliases Adding Utility To Make C++'s Type System Help Us Catch Bugs We're having an issue in JD3 right now where we have a lot of Sizes and Reals floating around and we are forced to use variable/parameter names to make sure they line up correctly when calling functions. This is very bug prone because the compiler will not tell you if you pass the wrong arguments if all of them are the same type (`core::Size`, for example). This PR adds a theoretically zero-overhead way to assign different type names to different Sizes. See below for an example. I'm also adding a few use cases to the MC HBNet data structure to make sure this works and to make sure the HBNet profile test does not get worse. ```c++ //OLD: void draw_rectangle( int width, int height ); void foo( int h, int w ){ draw_rectangle( h, w ); //logic error, may not be caught at runtime draw_rectangle( w, h ); //correct } //NEW: using Width = utility::StrongSize< struct Width_ >; using Height = utility::StrongSize< struct Height_ >; void draw_rectangle( Width width, Height height ); void foo( Size h, Size w ){ draw_rectangle( h, w ); //compiler error draw_rectangle( w, h ); //compiler error draw_rectangle( Width( h ), Height( w ) ); //logic error, but the developer should be able to notice that this is wrong draw_rectangle( Width( w ), Height( h ) ); //correct } ``` Here's proof that this abstraction gets compiled away: https://godbolt.org/z/eWM_uJ

...