libzypp 17.31.23
defaultintegral.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#ifndef ZYPP_CORE_BASE_DEFAULTINTEGRAL_H
13#define ZYPP_CORE_BASE_DEFAULTINTEGRAL_H
14
15#include <iosfwd>
16#include <boost/static_assert.hpp>
17#include <boost/type_traits/is_integral.hpp>
18
20namespace zypp
21{
22
23
25 //
26 // CLASS NAME : DefaultIntegral<Tp,TInitial>
27 //
40 template<class Tp, Tp TInitial>
42 {
43 public:
44 typedef Tp value_type;
45
46 public:
47 DefaultIntegral( Tp val_r = TInitial )
48 : _val( val_r )
49 { BOOST_STATIC_ASSERT(boost::is_integral<Tp>::value); }
50
53 Tp & get() { return _val; }
54 Tp get() const { return _val; }
55
56 operator Tp &() { return get(); }
57 operator Tp () const { return get(); }
59
61 constexpr Tp initial() const { return TInitial; }
62
64 DefaultIntegral & reset() { _val = TInitial; return *this; }
65
70 DefaultIntegral & operator=( Tp rhs ) { _val = rhs; return *this; }
71 DefaultIntegral & operator+=( Tp rhs ) { _val += rhs; return *this; }
72 DefaultIntegral & operator-=( Tp rhs ) { _val -= rhs; return *this; }
73 DefaultIntegral & operator*=( Tp rhs ) { _val *= rhs; return *this; }
74 DefaultIntegral & operator/=( Tp rhs ) { _val /= rhs; return *this; }
75
76 DefaultIntegral & operator++(/*prefix*/) { ++_val; return *this; }
77 DefaultIntegral & operator--(/*prefix*/) { --_val; return *this; }
78
79 DefaultIntegral operator++(int/*postfix*/) { return _val++; }
80 DefaultIntegral operator--(int/*postfix*/) { return _val--; }
82
83 private:
84 Tp _val;
85 };
86
89
92
94 template<typename TIntegral>
95 using ZeroInit = DefaultIntegral<TIntegral,TIntegral(0)>;
96
97 template<class Tp, Tp TInitial>
98 std::string asString( const DefaultIntegral<Tp,TInitial> & obj )
99 { return asString( obj.get() ); }
100
102} // namespace zypp
104#endif // ZYPP_CORE_BASE_DEFAULTINTEGRAL_H
Integral type with defined initial value when default constructed.
DefaultIntegral< bool, false > FalseBool
false initialized bool
DefaultIntegral & operator++()
DefaultIntegral & operator=(Tp rhs)
DefaultIntegral & operator+=(Tp rhs)
DefaultIntegral & operator--()
DefaultIntegral operator--(int)
constexpr Tp initial() const
The initial value.
DefaultIntegral< bool, true > TrueBool
true initialized bool
DefaultIntegral & operator-=(Tp rhs)
DefaultIntegral(Tp val_r=TInitial)
DefaultIntegral & operator/=(Tp rhs)
DefaultIntegral & operator*=(Tp rhs)
DefaultIntegral & reset()
Reset to the defined initial value.
Tp & get()
Conversion to Tp.
DefaultIntegral operator++(int)
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2