#ifndef BOOST_NUMERIC_SAFE_INTEGER_HPP #define BOOST_NUMERIC_SAFE_INTEGER_HPP // MS compatible compilers support #pragma once #if defined(_MSC_VER) && (_MSC_VER >= 1020) # pragma once #endif // Copyright (c) 2012 Robert Ramey // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #include "safe_base.hpp" #include "concept/numeric.hpp" #include "exception_policies.hpp" #include "native.hpp" #include "boost/concept/assert.hpp" // specialization for meta functions with safe argument namespace boost { namespace numeric { template< class T, class P, class E > struct safe; template< class T, class P, class E > struct is_safe > : public std::true_type {}; template< class T, class P, class E > struct get_promotion_policy > { typedef P type; }; template< class T, class P, class E > struct get_exception_policy > { typedef E type; }; template< class T, class P, class E > struct base_type > { typedef T type; }; template< class T, class P, class E > SAFE_NUMERIC_CONSTEXPR T base_value( const safe & st ) { return static_cast(st); } template< class T, class P = native, class E = throw_exception > struct safe : public safe_base, P, E>{ private: typedef safe_base, P, E > base_type; friend base_type; BOOST_CONCEPT_ASSERT((Integer)); BOOST_CONCEPT_ASSERT((PromotionPolicy

)); BOOST_CONCEPT_ASSERT((ExceptionPolicy)); SAFE_NUMERIC_CONSTEXPR static const T min(){ return std::numeric_limits::min(); } SAFE_NUMERIC_CONSTEXPR static const T max(){ return std::numeric_limits::max(); } public: // note: Rule of Three. Don't specify custom move, copy etc. SAFE_NUMERIC_CONSTEXPR safe() : base_type() {} template SAFE_NUMERIC_CONSTEXPR safe(const U & u) : base_type(u) {} }; } // numeric } // boost ///////////////////////////////////////////////////////////////// // numeric limits for safe etc. #include namespace std { template< class T, class P, class E > class numeric_limits > : public std::numeric_limits { typedef boost::numeric::safe SI; public: // these expressions are not SAFE_NUMERIC_CONSTEXPR until C++14 so re-implement them here SAFE_NUMERIC_CONSTEXPR static SI min() noexcept { return boost::numeric::safe(std::numeric_limits::min()); } SAFE_NUMERIC_CONSTEXPR static SI max() noexcept { return boost::numeric::safe(std::numeric_limits::max()); } }; } // std #include "safe_base_operations.hpp" #endif // BOOST_NUMERIC_SAFE_INTEGER_HPP