2 * Copyright Andrey Semashev 2007 - 2015.
3 * Distributed under the Boost Software License, Version 1.0.
4 * (See accompanying file LICENSE_1_0.txt or copy at
5 * http://www.boost.org/LICENSE_1_0.txt)
8 * \file tagged_integer.hpp
9 * \author Andrey Semashev
12 * \brief This header is the Boost.Log library implementation, see the library documentation
13 * at http://www.boost.org/doc/libs/release/libs/log/doc/html/index.html.
16 #ifndef BOOST_LOG_TAGGED_INTEGER_HPP_INCLUDED_
17 #define BOOST_LOG_TAGGED_INTEGER_HPP_INCLUDED_
19 #include <boost/log/detail/config.hpp>
20 #include <boost/log/detail/header.hpp>
22 #ifdef BOOST_HAS_PRAGMA_ONCE
28 BOOST_LOG_OPEN_NAMESPACE
32 //! A tagged integer wrapper for type safety
33 template< typename IntT, typename TagT >
36 //! Contained value type
37 typedef IntT integer_type;
44 //! Conversion operator
45 BOOST_CONSTEXPR operator integer_type() const BOOST_NOEXCEPT { return value; }
48 tagged_integer& operator++ () BOOST_NOEXCEPT { ++value; return *this; }
49 tagged_integer operator++ (int) BOOST_NOEXCEPT { tagged_integer temp = *this; ++value; return temp; }
51 tagged_integer& operator-- () BOOST_NOEXCEPT { --value; return *this; }
52 tagged_integer operator-- (int) BOOST_NOEXCEPT { tagged_integer temp = *this; --value; return temp; }
54 #define BOOST_LOG_TAGGED_INTEGER_OP(op)\
55 tagged_integer& operator op (tagged_integer const& that) BOOST_NOEXCEPT { value op that.value; return *this; }
57 BOOST_LOG_TAGGED_INTEGER_OP(|=)
58 BOOST_LOG_TAGGED_INTEGER_OP(&=)
59 BOOST_LOG_TAGGED_INTEGER_OP(^=)
60 BOOST_LOG_TAGGED_INTEGER_OP(+=)
61 BOOST_LOG_TAGGED_INTEGER_OP(-=)
62 BOOST_LOG_TAGGED_INTEGER_OP(*=)
63 BOOST_LOG_TAGGED_INTEGER_OP(/=)
64 BOOST_LOG_TAGGED_INTEGER_OP(%=)
66 #undef BOOST_LOG_TAGGED_INTEGER_OP
68 //! Inversion operator
69 tagged_integer& operator~ () BOOST_NOEXCEPT { ~value; return *this; }
72 template< typename T >
73 tagged_integer& operator<<= (T const& that) BOOST_NOEXCEPT { value <<= that; return *this; }
74 template< typename T >
75 tagged_integer& operator>>= (T const& that) BOOST_NOEXCEPT { value >>= that; return *this; }
78 // Protection against improper usage
79 template< typename T1, typename T2 >
80 tagged_integer& operator<<= (tagged_integer< T1, T2 > const&);
81 template< typename T1, typename T2 >
82 tagged_integer& operator>>= (tagged_integer< T1, T2 > const&);
85 // Relational operators
86 #define BOOST_LOG_TAGGED_INTEGER_OP(op)\
87 template< typename IntT, typename TagT >\
88 inline bool operator op (\
89 tagged_integer< IntT, TagT > const& left, tagged_integer< IntT, TagT > const& right) BOOST_NOEXCEPT\
91 return (left.value op right.value);\
94 BOOST_LOG_TAGGED_INTEGER_OP(==)
95 BOOST_LOG_TAGGED_INTEGER_OP(!=)
96 BOOST_LOG_TAGGED_INTEGER_OP(<)
97 BOOST_LOG_TAGGED_INTEGER_OP(>)
98 BOOST_LOG_TAGGED_INTEGER_OP(<=)
99 BOOST_LOG_TAGGED_INTEGER_OP(>=)
101 #undef BOOST_LOG_TAGGED_INTEGER_OP
103 #define BOOST_LOG_TAGGED_INTEGER_OP(op)\
104 template< typename IntT, typename TagT >\
105 inline tagged_integer< IntT, TagT > operator op (\
106 tagged_integer< IntT, TagT > const& left, tagged_integer< IntT, TagT > const& right) BOOST_NOEXCEPT\
108 tagged_integer< IntT, TagT > temp = left;\
113 BOOST_LOG_TAGGED_INTEGER_OP(|)
114 BOOST_LOG_TAGGED_INTEGER_OP(&)
115 BOOST_LOG_TAGGED_INTEGER_OP(^)
116 BOOST_LOG_TAGGED_INTEGER_OP(+)
117 BOOST_LOG_TAGGED_INTEGER_OP(-)
118 BOOST_LOG_TAGGED_INTEGER_OP(*)
119 BOOST_LOG_TAGGED_INTEGER_OP(/)
120 BOOST_LOG_TAGGED_INTEGER_OP(%)
122 #undef BOOST_LOG_TAGGED_INTEGER_OP
124 #define BOOST_LOG_TAGGED_INTEGER_OP(op)\
125 template< typename IntT, typename TagT, typename T >\
126 inline tagged_integer< IntT, TagT > operator op (\
127 tagged_integer< IntT, TagT > const& left, T const& right) BOOST_NOEXCEPT\
129 tagged_integer< IntT, TagT > temp = left;\
134 BOOST_LOG_TAGGED_INTEGER_OP(<<)
135 BOOST_LOG_TAGGED_INTEGER_OP(>>)
137 #undef BOOST_LOG_TAGGED_INTEGER_OP
141 BOOST_LOG_CLOSE_NAMESPACE // namespace log
145 #include <boost/log/detail/footer.hpp>
147 #endif // BOOST_LOG_TAGGED_INTEGER_HPP_INCLUDED_