On 2021-01-07 at 15:50, Alexander Grund via Boost wrote:
(I'm sorry to hijack a little bit) You can send a new mail with a new topic I am planning to implement units in YADE [1][2], and initially I wanted to use _m _km _s names, so that I could write: 1.0_km instead of 1.0km
Then I decided against it, because of UB. Then I saw in boost ublas tensor this example:
Which is using exactly the notation which I need: 10_kPa is easier to read than 10kPa, or 10_Pa vs 10Pa
So. Where exactly do we have UB ? Would simply putting it into separate namespace yade::units solve the problem?
Are there only certain letters forbidden after a starting underscore? All names beginning with double-underscore or underscore+capital are forbidden.
https://en.cppreference.com/w/cpp/language/user_literal shows that `_Z` is fine:
double operator"" _Z(long double); // error: all names that begin with underscore // followed by uppercase letter are reserved double operator""_Z(long double); // OK: even though _Z is reserved ""_Z is allowed
So yes _Pa is fine as long as you write your UDL in the 2nd version
Yes, literal operators somehow seem to have the opposite rule of other reserved names. Here names with underscores are reserved for user programs, and the non-underscore names are used by the standard library. We even have a complex<float> operator""if(), even though if is a reserved keyword everywhere else. Odd, isn't it? :-) Bo Persson