Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:51:12

0001 /* boost random/traits.hpp header file
0002  *
0003  * Copyright John Maddock 2015
0004  * Distributed under the Boost Software License, Version 1.0. (See
0005  * accompanying file LICENSE_1_0.txt or copy at
0006  * http://www.boost.org/LICENSE_1_0.txt)
0007  *
0008  * See http://www.boost.org for most recent version including documentation.
0009  *
0010  * These traits classes serve two purposes: they are designed to mostly
0011  * work out of the box for multiprecision types (ie number types that are
0012  * C++ class types and not integers or floats from type-traits point of view),
0013  * they are also a potential point of specialization for user-defined
0014  * number types.
0015  *
0016  * $Id$
0017  */
0018 
0019 #ifndef BOOST_RANDOM_TRAITS_HPP
0020 #define BOOST_RANDOM_TRAITS_HPP
0021 
0022 #include <boost/type_traits/integral_constant.hpp>
0023 #include <boost/type_traits/is_signed.hpp>
0024 #include <boost/type_traits/is_integral.hpp>
0025 #include <boost/type_traits/make_unsigned.hpp>
0026 #include <limits>
0027 
0028 namespace boost {
0029 namespace random {
0030 namespace traits {
0031    // \cond show_private
0032    template <class T, bool intrinsic>
0033    struct make_unsigned_imp
0034    {
0035       typedef typename boost::make_unsigned<T>::type type;
0036    };
0037    template <class T>
0038    struct make_unsigned_imp<T, false>
0039    {
0040       BOOST_STATIC_ASSERT(std::numeric_limits<T>::is_specialized);
0041       BOOST_STATIC_ASSERT(std::numeric_limits<T>::is_signed == false);
0042       BOOST_STATIC_ASSERT(std::numeric_limits<T>::is_integer == true);
0043       typedef T type;
0044    };
0045    // \endcond
0046    /** \brief Converts the argument type T to an unsigned type.
0047    *
0048    * This trait has a single member `type` which is the unsigned type corresponding to T.
0049    * Note that
0050    * if T is signed, then member `type` *should define a type with one more bit precision than T*.  For built-in
0051    * types this trait defaults to `boost::make_unsigned<T>::type`.  For user defined types it simply asserts that
0052    * the argument type T is an unsigned integer (using std::numeric_limits).
0053    * User defined specializations may be provided for other cases.
0054    */
0055    template <class T>
0056    struct make_unsigned
0057    // \cond show_private
0058       : public make_unsigned_imp < T, boost::is_integral<T>::value > 
0059       // \endcond
0060    {};
0061    // \cond show_private
0062    template <class T, bool intrinsic>
0063    struct make_unsigned_or_unbounded_imp
0064    {
0065       typedef typename boost::make_unsigned<T>::type type;
0066    };
0067    template <class T>
0068    struct make_unsigned_or_unbounded_imp<T, false>
0069    {
0070       BOOST_STATIC_ASSERT(std::numeric_limits<T>::is_specialized);
0071       BOOST_STATIC_ASSERT((std::numeric_limits<T>::is_signed == false) || (std::numeric_limits<T>::is_bounded == false));
0072       BOOST_STATIC_ASSERT(std::numeric_limits<T>::is_integer == true);
0073       typedef T type;
0074    };
0075    // \endcond
0076    /** \brief Converts the argument type T to either an unsigned type or an unbounded integer type.
0077    *
0078    * This trait has a single member `type` which is either the unsigned type corresponding to T or an unbounded
0079    * integer type.  This trait is used to generate types suitable for the calculation of a range: as a result
0080    * if T is signed, then member `type` *should define a type with one more bit precision than T*.  For built-in
0081    * types this trait defaults to `boost::make_unsigned<T>::type`.  For user defined types it simply asserts that
0082    * the argument type T is either an unbounded integer, or an unsigned one (using std::numeric_limits).
0083    * User defined specializations may be provided for other cases.
0084    */
0085    template <class T>
0086    struct make_unsigned_or_unbounded
0087       // \cond show_private
0088       : public make_unsigned_or_unbounded_imp < T, boost::is_integral<T>::value > 
0089       // \endcond
0090    {};
0091    /** \brief Traits class that indicates whether type T is an integer
0092    */
0093    template <class T>
0094    struct is_integral
0095       : public integral_constant<bool, boost::is_integral<T>::value || (std::numeric_limits<T>::is_integer)>
0096    {};
0097    /** \brief Traits class that indicates whether type T is a signed integer
0098    */
0099    template <class T> struct is_signed
0100       : public integral_constant<bool, boost::is_signed<T>::value || (std::numeric_limits<T>::is_specialized && std::numeric_limits<T>::is_integer && std::numeric_limits<T>::is_signed)>
0101    {};
0102 
0103 }
0104 }
0105 }
0106 
0107 #endif