diff --git a/doc/gcd/math-gcd.qbk b/doc/gcd/math-gcd.qbk index 4d3edd6..346050c 100644 --- a/doc/gcd/math-gcd.qbk +++ b/doc/gcd/math-gcd.qbk @@ -24,9 +24,9 @@ programming problems. class lcm_evaluator; template < typename IntegerType > - IntegerType gcd( IntegerType const &a, IntegerType const &b ); + constexpr IntegerType gcd( IntegerType const &a, IntegerType const &b ); template < typename IntegerType > - IntegerType lcm( IntegerType const &a, IntegerType const &b ); + constexpr IntegerType lcm( IntegerType const &a, IntegerType const &b ); typedef ``['see-below]`` static_gcd_type; @@ -54,8 +54,9 @@ programming problems. typedef IntegerType second_argument_type; // Function object interface - result_type operator ()( first_argument_type const &a, - second_argument_type const &b ) const; + constexpr result_type operator ()( + first_argument_type const &a, + second_argument_type const &b ) const; }; The boost::math::gcd_evaluator class template defines a function object @@ -70,6 +71,9 @@ the GCD function template. If a numeric type wants to customize evaluations of its greatest common divisors, then the type should specialize on the gcd_evaluator class template. +Note that these function objects are `constexpr` in C++14 and later only. +They are also declared `noexcept` when appropriate. + [endsect] [section LCM Function Object] @@ -86,8 +90,9 @@ gcd_evaluator class template. typedef IntegerType second_argument_type; // Function object interface - result_type operator ()( first_argument_type const &a, - second_argument_type const &b ) const; + constexpr result_type operator ()( + first_argument_type const &a, + second_argument_type const &b ) const; }; The boost::math::lcm_evaluator class template defines a function object @@ -103,6 +108,9 @@ of the LCM function template. If a numeric type wants to customize evaluations of its least common multiples, then the type should specialize on the lcm_evaluator class template. +Note that these function objects are constexpr in C++14 and later only. +They are also declared `noexcept` when appropriate. + [endsect] [section:run_time Run-time GCD & LCM Determination] @@ -110,10 +118,10 @@ specialize on the lcm_evaluator class template. [*Header: ] [@../../../../boost/math/common_factor_rt.hpp ] template < typename IntegerType > - IntegerType boost::math::gcd( IntegerType const &a, IntegerType const &b ); + constexpr IntegerType boost::math::gcd( IntegerType const &a, IntegerType const &b ); template < typename IntegerType > - IntegerType boost::math::lcm( IntegerType const &a, IntegerType const &b ); + constexpr IntegerType boost::math::lcm( IntegerType const &a, IntegerType const &b ); The boost::math::gcd function template returns the greatest common (nonnegative) divisor of the two integers passed to it. @@ -124,6 +132,9 @@ IntegerType, which is also the return type. Internally, these function templates use an object of the corresponding version of the gcd_evaluator and lcm_evaluator class templates, respectively. +Note that these functions are constexpr in C++14 and later only. +They are also declared `noexcept` when appropriate. + [endsect] [section:compile_time Compile time GCD and LCM determination] diff --git a/doc/html/boost_integer/cstdint.html b/doc/html/boost_integer/cstdint.html index 2aeb66a..cb0223f 100644 --- a/doc/html/boost_integer/cstdint.html +++ b/doc/html/boost_integer/cstdint.html @@ -3,7 +3,7 @@ Removed from library: Standard Integer Types - + diff --git a/doc/html/boost_integer/history.html b/doc/html/boost_integer/history.html index 4248b7c..77257ba 100644 --- a/doc/html/boost_integer/history.html +++ b/doc/html/boost_integer/history.html @@ -3,7 +3,7 @@ History - + diff --git a/doc/html/boost_integer/integer.html b/doc/html/boost_integer/integer.html index 082e1d7..825ecf4 100644 --- a/doc/html/boost_integer/integer.html +++ b/doc/html/boost_integer/integer.html @@ -3,7 +3,7 @@ Integer Type Selection - + @@ -26,7 +26,7 @@

Integer Type Selection

-
+
Synopsis
Easiest-to-Manipulate Types
diff --git a/doc/html/boost_integer/log2.html b/doc/html/boost_integer/log2.html index 2749cf2..19c1a21 100644 --- a/doc/html/boost_integer/log2.html +++ b/doc/html/boost_integer/log2.html @@ -3,7 +3,7 @@ Compile Time log2 Calculation - + @@ -26,7 +26,7 @@ -
+
Synopsis
Usage
Demonstration diff --git a/doc/html/boost_integer/mask.html b/doc/html/boost_integer/mask.html index 1cf8892..05c0f77 100644 --- a/doc/html/boost_integer/mask.html +++ b/doc/html/boost_integer/mask.html @@ -3,7 +3,7 @@ Integer Masks - + @@ -26,7 +26,7 @@ -
+
Overview
Synopsis
Single diff --git a/doc/html/boost_integer/minmax.html b/doc/html/boost_integer/minmax.html index 1fae3ad..d67425f 100644 --- a/doc/html/boost_integer/minmax.html +++ b/doc/html/boost_integer/minmax.html @@ -3,7 +3,7 @@ Compile time min/max calculation - + @@ -26,7 +26,7 @@ -
+
Synopsis
Usage
Example
diff --git a/doc/html/boost_integer/traits.html b/doc/html/boost_integer/traits.html index 90a5188..76987ad 100644 --- a/doc/html/boost_integer/traits.html +++ b/doc/html/boost_integer/traits.html @@ -3,7 +3,7 @@ Integer Traits - + @@ -26,7 +26,7 @@ -
+
Motivation
Synopsis
Description
diff --git a/doc/html/index.html b/doc/html/index.html index 2217d35..90fe0b7 100644 --- a/doc/html/index.html +++ b/doc/html/index.html @@ -3,7 +3,7 @@ Boost.Integer - + @@ -50,7 +50,7 @@

Table of Contents

-
+
Overview
Integer Traits
Integer Type Selection
@@ -219,7 +219,7 @@
- +

Last revised: June 01, 2014 at 19:57:36 GMT

Last revised: March 28, 2017 at 17:56:42 GMT


diff --git a/include/boost/integer/common_factor_rt.hpp b/include/boost/integer/common_factor_rt.hpp index c2b54db..64224e4 100644 --- a/include/boost/integer/common_factor_rt.hpp +++ b/include/boost/integer/common_factor_rt.hpp @@ -22,6 +22,10 @@ #include // for CHAR_MIN #include +#ifndef BOOST_NO_CXX11_NOEXCEPT +#include +#endif + #ifdef BOOST_MSVC #pragma warning(push) #pragma warning(disable:4127 4244) // Conditional expression is constant @@ -32,14 +36,15 @@ namespace boost namespace integer { +#define BOOST_INT_NOEXCEPT(T) BOOST_NOEXCEPT_IF(boost::is_arithmetic::value) // Forward declarations for function templates -----------------------------// template < typename IntegerType > - IntegerType gcd( IntegerType const &a, IntegerType const &b ); +BOOST_CXX14_CONSTEXPR IntegerType gcd( IntegerType const &a, IntegerType const &b )BOOST_INT_NOEXCEPT(IntegerType); template < typename IntegerType > - IntegerType lcm( IntegerType const &a, IntegerType const &b ); +BOOST_CXX14_CONSTEXPR IntegerType lcm( IntegerType const &a, IntegerType const &b )BOOST_INT_NOEXCEPT(IntegerType); // Greatest common divisor evaluator class declaration ---------------------// @@ -52,8 +57,8 @@ public: typedef IntegerType result_type, first_argument_type, second_argument_type; // Function object interface - result_type operator ()( first_argument_type const &a, - second_argument_type const &b ) const; + BOOST_CXX14_CONSTEXPR result_type operator ()( first_argument_type const &a, + second_argument_type const &b )const BOOST_INT_NOEXCEPT(IntegerType) ; }; // boost::integer::gcd_evaluator @@ -68,8 +73,8 @@ public: typedef IntegerType result_type, first_argument_type, second_argument_type; // Function object interface - result_type operator ()( first_argument_type const &a, - second_argument_type const &b ) const; + BOOST_CXX14_CONSTEXPR result_type operator ()( first_argument_type const &a, + second_argument_type const &b )const BOOST_INT_NOEXCEPT(IntegerType) ; }; // boost::integer::lcm_evaluator @@ -80,12 +85,12 @@ namespace detail { // Greatest common divisor for rings (including unsigned integers) template < typename RingType > - RingType + BOOST_CXX14_CONSTEXPR RingType gcd_euclidean ( RingType a, RingType b - ) + )BOOST_INT_NOEXCEPT(RingType) { // Avoid repeated construction #ifndef __BORLANDC__ @@ -110,12 +115,12 @@ namespace detail // Greatest common divisor for (signed) integers template < typename IntegerType > inline - IntegerType + BOOST_CXX14_CONSTEXPR IntegerType gcd_integer ( IntegerType const & a, IntegerType const & b - ) + )BOOST_INT_NOEXCEPT(IntegerType) { // Avoid repeated construction IntegerType const zero = static_cast( 0 ); @@ -126,12 +131,12 @@ namespace detail // Greatest common divisor for unsigned binary integers template < typename BuiltInUnsigned > - BuiltInUnsigned + BOOST_CXX14_CONSTEXPR BuiltInUnsigned gcd_binary ( BuiltInUnsigned u, BuiltInUnsigned v - ) + )BOOST_INT_NOEXCEPT(BuiltInUnsigned) { if ( u && v ) { @@ -190,12 +195,12 @@ namespace detail // Least common multiple for rings (including unsigned integers) template < typename RingType > inline - RingType + BOOST_CXX14_CONSTEXPR RingType lcm_euclidean ( RingType const & a, RingType const & b - ) + )BOOST_INT_NOEXCEPT(RingType) { RingType const zero = static_cast( 0 ); RingType const temp = gcd_euclidean( a, b ); @@ -205,13 +210,13 @@ namespace detail // Least common multiple for (signed) integers template < typename IntegerType > - inline + inline BOOST_CXX14_CONSTEXPR IntegerType lcm_integer ( IntegerType const & a, IntegerType const & b - ) + )BOOST_INT_NOEXCEPT(IntegerType) { // Avoid repeated construction IntegerType const zero = static_cast( 0 ); @@ -225,7 +230,7 @@ namespace detail template < typename T, bool IsSpecialized, bool IsSigned > struct gcd_optimal_evaluator_helper_t { - T operator ()( T const &a, T const &b ) + BOOST_CXX14_CONSTEXPR T operator ()( T const &a, T const &b )BOOST_INT_NOEXCEPT(T) { return gcd_euclidean( a, b ); } @@ -234,7 +239,7 @@ namespace detail template < typename T > struct gcd_optimal_evaluator_helper_t< T, true, true > { - T operator ()( T const &a, T const &b ) + BOOST_CXX14_CONSTEXPR T operator ()( T const &a, T const &b )BOOST_INT_NOEXCEPT(T) { return gcd_integer( a, b ); } @@ -243,7 +248,7 @@ namespace detail template < typename T > struct gcd_optimal_evaluator { - T operator ()( T const &a, T const &b ) + BOOST_CXX14_CONSTEXPR T operator ()( T const &a, T const &b )BOOST_INT_NOEXCEPT(T) { typedef ::std::numeric_limits limits_type; @@ -259,7 +264,7 @@ namespace detail template < typename T > struct gcd_optimal_evaluator { - T operator ()( T const &a, T const &b ) + BOOST_CXX14_CONSTEXPR T operator ()( T const &a, T const &b )BOOST_INT_NOEXCEPT(T) { return gcd_integer( a, b ); } @@ -269,7 +274,7 @@ namespace detail // Specialize for the built-in integers #define BOOST_PRIVATE_GCD_UF( Ut ) \ template < > struct gcd_optimal_evaluator \ - { Ut operator ()( Ut a, Ut b ) const { return gcd_binary( a, b ); } } + { BOOST_CXX14_CONSTEXPR Ut operator ()( Ut a, Ut b ) const BOOST_INT_NOEXCEPT(Ut) { return gcd_binary( a, b ); } } BOOST_PRIVATE_GCD_UF( unsigned char ); BOOST_PRIVATE_GCD_UF( unsigned short ); @@ -290,7 +295,7 @@ namespace detail #define BOOST_PRIVATE_GCD_SF( St, Ut ) \ template < > struct gcd_optimal_evaluator \ - { St operator ()( St a, St b ) const { Ut const a_abs = \ + { BOOST_CXX14_CONSTEXPR St operator ()( St a, St b ) const BOOST_INT_NOEXCEPT(St) { Ut const a_abs = \ static_cast( a < 0 ? -a : +a ), b_abs = static_cast( \ b < 0 ? -b : +b ); return static_cast( \ gcd_optimal_evaluator()(a_abs, b_abs) ); } } @@ -316,7 +321,7 @@ namespace detail template < typename T, bool IsSpecialized, bool IsSigned > struct lcm_optimal_evaluator_helper_t { - T operator ()( T const &a, T const &b ) + BOOST_CXX14_CONSTEXPR T operator ()( T const &a, T const &b )BOOST_INT_NOEXCEPT(T) { return lcm_euclidean( a, b ); } @@ -325,7 +330,7 @@ namespace detail template < typename T > struct lcm_optimal_evaluator_helper_t< T, true, true > { - T operator ()( T const &a, T const &b ) + BOOST_CXX14_CONSTEXPR T operator ()( T const &a, T const &b )BOOST_INT_NOEXCEPT(T) { return lcm_integer( a, b ); } @@ -334,7 +339,7 @@ namespace detail template < typename T > struct lcm_optimal_evaluator { - T operator ()( T const &a, T const &b ) + BOOST_CXX14_CONSTEXPR T operator ()( T const &a, T const &b )BOOST_INT_NOEXCEPT(T) { typedef ::std::numeric_limits limits_type; @@ -350,7 +355,7 @@ namespace detail template < typename T > struct lcm_optimal_evaluator { - T operator ()( T const &a, T const &b ) + BOOST_CXX14_CONSTEXPR T operator ()( T const &a, T const &b )BOOST_INT_NOEXCEPT(T) { return lcm_integer( a, b ); } @@ -359,13 +364,13 @@ namespace detail // Functions to find the GCD or LCM in the best way template < typename T > - inline + inline BOOST_CXX14_CONSTEXPR T gcd_optimal ( T const & a, T const & b - ) + )BOOST_INT_NOEXCEPT(T) { gcd_optimal_evaluator solver; @@ -373,13 +378,13 @@ namespace detail } template < typename T > - inline + inline BOOST_CXX14_CONSTEXPR T lcm_optimal ( T const & a, T const & b - ) + )BOOST_INT_NOEXCEPT(T) { lcm_optimal_evaluator solver; @@ -392,13 +397,13 @@ namespace detail // Greatest common divisor evaluator member function definition ------------// template < typename IntegerType > -inline +inline BOOST_CXX14_CONSTEXPR typename gcd_evaluator::result_type gcd_evaluator::operator () ( first_argument_type const & a, second_argument_type const & b -) const +) const BOOST_INT_NOEXCEPT(IntegerType) { return detail::gcd_optimal( a, b ); } @@ -407,13 +412,13 @@ gcd_evaluator::operator () // Least common multiple evaluator member function definition --------------// template < typename IntegerType > -inline +inline BOOST_CXX14_CONSTEXPR typename lcm_evaluator::result_type lcm_evaluator::operator () ( first_argument_type const & a, second_argument_type const & b -) const +) const BOOST_INT_NOEXCEPT(IntegerType) { return detail::lcm_optimal( a, b ); } @@ -422,13 +427,13 @@ lcm_evaluator::operator () // Greatest common divisor and least common multiple function definitions --// template < typename IntegerType > -inline +inline BOOST_CXX14_CONSTEXPR IntegerType gcd ( IntegerType const & a, IntegerType const & b -) +) BOOST_INT_NOEXCEPT(IntegerType) { gcd_evaluator solver; @@ -436,13 +441,13 @@ gcd } template < typename IntegerType > -inline +inline BOOST_CXX14_CONSTEXPR IntegerType lcm ( IntegerType const & a, IntegerType const & b -) +) BOOST_INT_NOEXCEPT(IntegerType) { lcm_evaluator solver;