libzypp  17.18.0
Easy.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_BASE_EASY_H
13 #define ZYPP_BASE_EASY_H
14 
15 #include <cstdio>
16 #include <type_traits>
17 
27 #ifndef __GXX_EXPERIMENTAL_CXX0X__
28 #define for_(IT,BEG,END) for ( __typeof__(BEG) IT = BEG, _for_end = END; IT != _for_end; ++IT )
29 #else
30 #define for_(IT,BEG,END) for ( auto IT = BEG, _for_end = END; IT != _for_end; ++IT )
31 #endif
32 #define for_each_(IT,CONT) for_( IT, (CONT).begin(), (CONT).end() )
33 
41 #define arrayBegin(A) (&A[0])
42 #define arraySize(A) (sizeof(A)/sizeof(*A))
43 #define arrayEnd(A) (&A[0] + arraySize(A))
44 
51 #define defConstStr(FNC,STR) inline const std::string & FNC { static const std::string val( STR ); return val; }
52 
53 #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
54 #if GCC_VERSION < 40600 || not defined(__GXX_EXPERIMENTAL_CXX0X__)
55 #define nullptr NULL
56 #endif
57 
59 #define NON_COPYABLE(CLASS) \
60  CLASS( const CLASS & ) = delete; \
61  CLASS & operator=( const CLASS & ) = delete
62 
64 #define DEFAULT_COPYABLE(CLASS) \
65  CLASS( const CLASS & ) = default; \
66  CLASS & operator=( const CLASS & ) = default
67 
68 #ifndef SWIG // Swig treats it as syntax error
69 
70 #define NON_MOVABLE(CLASS) \
71  CLASS( CLASS && ) = delete; \
72  CLASS & operator=( CLASS && ) = delete
73 
75 #define DEFAULT_MOVABLE(CLASS) \
76  CLASS( CLASS && ) = default; \
77  CLASS & operator=( CLASS && ) = default
78 #else
79 #define NON_MOVABLE(CLASS)
80 #define DEFAULT_MOVABLE(CLASS)
81 #endif
82 
84 #define NON_COPYABLE_BUT_MOVE( CLASS ) \
85  NON_COPYABLE(CLASS); \
86  DEFAULT_MOVABLE(CLASS)
87 
89 #define NON_MOVABLE_BUT_COPY( CLASS ) \
90  NON_MOVABLE(CLASS); \
91  DEFAULT_COPYABLE(CLASS)
92 
93 
112 template<typename TBase, typename TDerived>
113 using disable_use_as_copy_ctor = typename std::enable_if<!std::is_base_of<TBase,typename std::remove_reference<TDerived>::type>::value>::type;
114 
116 namespace zypp
117 {
118 } // namespace zypp
121 #endif // ZYPP_BASE_EASY_H
typename std::enable_if<!std::is_base_of< TBase, typename std::remove_reference< TDerived >::type >::value >::type disable_use_as_copy_ctor
Prevent an universal ctor to be chosen as copy ctor.
Definition: Easy.h:113
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1