supernova: c++11 compile fixes
[supercollider.git] / external_libraries / boost_endian / boost / integer / cover_operators.hpp
blob56cf3c8f105fcfb3acff1cb45bef3656d42aaf7e
1 // boost/integer/cover_operators.hpp ----------------------------------------//
3 // Copyright Darin Adler 2000
4 // Copyright Beman Dawes 2008
6 // Distributed under the Boost Software License, Version 1.0. (See accompanying
7 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 //----------------------------------------------------------------------------//
11 // If the class being covered has a non-explicit conversion to an integer type
12 // then a smaller number of cover operations are needed. Define the macro
13 // BOOST_MINIMAL_INTEGER_COVER_OPERATORS to indicate this.
15 // Define BOOST_NO_IO_COVER_OPERATORS if I/O cover operations are not desired.
17 //----------------------------------------------------------------------------//
19 #ifndef BOOST_INTEGER_COVER_OPERATORS_HPP
20 #define BOOST_INTEGER_COVER_OPERATORS_HPP
22 # ifndef BOOST_MINIMAL_INTEGER_COVER_OPERATORS
23 # include <boost/operators.hpp>
24 # endif
26 #include <iosfwd>
28 namespace boost
30 namespace integer
33 // A class that adds integer operators to an integer cover class
35 template <typename T, typename IntegerType>
36 class cover_operators
37 # ifndef BOOST_MINIMAL_INTEGER_COVER_OPERATORS
38 : boost::operators<T>
39 # endif
41 // The other operations take advantage of the type conversion that's
42 // built into unary +.
44 // Unary operations.
45 friend IntegerType operator+(const T& x) { return x; }
46 # ifndef BOOST_MINIMAL_INTEGER_COVER_OPERATORS
47 friend IntegerType operator-(const T& x) { return -+x; }
48 friend IntegerType operator~(const T& x) { return ~+x; }
49 friend IntegerType operator!(const T& x) { return !+x; }
51 // The basic ordering operations.
52 friend bool operator==(const T& x, IntegerType y) { return +x == y; }
53 friend bool operator<(const T& x, IntegerType y) { return +x < y; }
54 # endif
56 // The basic arithmetic operations.
57 friend T& operator+=(T& x, IntegerType y) { return x = +x + y; }
58 friend T& operator-=(T& x, IntegerType y) { return x = +x - y; }
59 friend T& operator*=(T& x, IntegerType y) { return x = +x * y; }
60 friend T& operator/=(T& x, IntegerType y) { return x = +x / y; }
61 friend T& operator%=(T& x, IntegerType y) { return x = +x % y; }
62 friend T& operator&=(T& x, IntegerType y) { return x = +x & y; }
63 friend T& operator|=(T& x, IntegerType y) { return x = +x | y; }
64 friend T& operator^=(T& x, IntegerType y) { return x = +x ^ y; }
65 friend T& operator<<=(T& x, IntegerType y) { return x = +x << y; }
66 friend T& operator>>=(T& x, IntegerType y) { return x = +x >> y; }
68 // A few binary arithmetic operations not covered by operators base class.
69 friend IntegerType operator<<(const T& x, IntegerType y) { return +x << y; }
70 friend IntegerType operator>>(const T& x, IntegerType y) { return +x >> y; }
72 // Auto-increment and auto-decrement can be defined in terms of the
73 // arithmetic operations.
74 friend T& operator++(T& x) { return x += 1; }
75 friend T& operator--(T& x) { return x -= 1; }
77 # ifdef BOOST_MINIMAL_INTEGER_COVER_OPERATORS
78 friend T operator++(T& x, int)
80 T tmp(x);
81 x += 1;
82 return tmp;
84 friend T operator--(T& x, int)
86 T tmp(x);
87 x -= 1;
88 return tmp;
90 # endif
92 # ifndef BOOST_NO_IO_COVER_OPERATORS
93 // TODO: stream I/O needs to be templatized on the stream type, so will
94 // work with wide streams, etc.
96 // Stream input and output.
97 friend std::ostream& operator<<(std::ostream& s, const T& x)
98 { return s << +x; }
99 friend std::istream& operator>>(std::istream& s, T& x)
101 IntegerType i;
102 if (s >> i)
103 x = i;
104 return s;
106 # endif
108 } // namespace integer
109 } // namespace boost
111 #endif // BOOST_INTEGER_COVER_OPERATORS_HPP