[rational] make rational constructors noexcept
Hi, I think that some rational constructors can be marked noexcept. In particular: - default constructor: rational() - constructor from integer: rational(const T& n, typename enable_if_c<...>::type const* = 0) Concerning the constructor with numerator and denominator, if the denominator is always not null, it could be noexcept but I guess we cannot enforce not null unless we use some kind of gsl::not_null. Your thoughts? Thanks, F
On 06/08/2019 06:46, Frédéric via Boost-users wrote:
Hi,
I think that some rational constructors can be marked noexcept. In particular: - default constructor: rational() - constructor from integer: rational(const T& n, typename enable_if_c<...>::type const* = 0)
Careful: they would have to be conditionally noexcept to support multiprecision types which may throw on those operations (memory allocation).
Concerning the constructor with numerator and denominator, if the denominator is always not null, it could be noexcept but I guess we cannot enforce not null unless we use some kind of gsl::not_null.
Your thoughts?
Thanks,
F _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org https://lists.boost.org/mailman/listinfo.cgi/boost-users
--- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus
I think that some rational constructors can be marked noexcept. In particular: - default constructor: rational() - constructor from integer: rational(const T& n, typename enable_if_c<...>::type const* = 0)
Careful: they would have to be conditionally noexcept to support multiprecision types which may throw on those operations (memory allocation).
I see and the default constructor cannot use enable_if. The only possibility would be to have an additionnal bool template parameter is_pod<T> or has_nothrow_constructor<T>... Quite painful to implement. F
On 8/6/19 11:50 AM, Frédéric via Boost-users wrote:
I think that some rational constructors can be marked noexcept. In particular: - default constructor: rational() - constructor from integer: rational(const T& n, typename enable_if_c<...>::type const* = 0)
Careful: they would have to be conditionally noexcept to support multiprecision types which may throw on those operations (memory allocation).
Also, the safe numerics library uses boost rational to demonstrate the usage of safe numeric types as arguments to other "numeric" types. This is an example of a case where it makes sense for a type parameter to not be noexcept.
I see and the default constructor cannot use enable_if. The only possibility would be to have an additionnal bool template parameter is_pod<T> or has_nothrow_constructor<T>... Quite painful to implement.
F
participants (3)
-
Frédéric
-
John Maddock
-
Robert Ramey