Is there a reason not to use enforcement elements?

Conceptually, it seems to me that using single forced types (Meters, Seconds, Kilograms) will have enormous advantages (additional checking when passing args, getting rid of unit names in vars, etc.), and yet I have not come across as much code which does. And the code I saw that used used custom types.

I see that boost has a library of units (boost :: units is enough), and yet I donโ€™t see much evidence that it is widely used (mainly Google search).

Is there a good reason for this?

Together, they apparently mean that there must be some reason why the practice was not as widely accepted as I expected. Perhaps more problems than they are for some reason?

And so I ask:

Is there a reason not to use enforcement elements? In particular, is there a reason not to use boost :: units?

+6
source share
2 answers

I think the main reason this method is not more common is that it is terribly complex and cumbersome to write and read.

Hopefully this will finally become a more acceptable C ++ 11 programming style that will add custom literals to a language that allows you to write:

auto acc = 10_m / 1_s / 1_s; 

not traditional

 myframework::units::si<acceleration>::type acc = myframework::unit_cast<units::meters>(10.0) / myframework::unit_cast<units::seconds>(1) / myframework::unit_cast<units::seconds>(1); 
+6
source

I used this library for great benefit to write the correct code. Unfortunately, this is about 10 times more complicated than it should be. It's worth it anyway, although tracking sizes and units is a nightmare.

The accelerator block library is very smart, powerful, and complete. The problem is that the documentation is almost unreadable. There are many problems with confusing names, without type requirements. The authors have included many examples that are useful but do not replace a more advanced document.

FYI - I presented a tutorial on this subject at CPPcon 2015. You can find it at https://www.youtube.com/watch?v=qphj8ZuZlPA

+3
source

Source: https://habr.com/ru/post/926224/


All Articles