Files
safe_numerics/include/automatic.hpp

46 lines
1.2 KiB
C++

#ifndef BOOST_NUMERIC_AUTOMATIC_HPP
#define BOOST_NUMERIC_AUTOMATIC_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)
// we could have used decltype and auto for C++11 but we've decided
// to use boost/typeof to be compatible with older compilers
#include <boost/typeof/typeof.hpp>
// policy which creates results types equal to that of C++ promotions.
// Using the policy will permit the program to build and run in release
// mode which is identical to that in debug mode except for the fact
// that errors aren't trapped.
namespace boost {
namespace numeric {
namespace promotion {
struct automatic {
template<
typename T,
typename U
>
struct addition_result {
typedef boost::numeric::safe_unsigned_range<
std::numeric_limits<T>::min() + std::numeric_limits<U>::min(),
std::numeric_limits<T>::max() + std::numeric_limits<U>::max(),
> type;
};
};
} // promotion
} // numeric
} // boost
#endif // BOOST_NUMERIC_AUTOMATIC_HPP