1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/base/Easy.h
12 #ifndef ZYPP_BASE_EASY_H
13 #define ZYPP_BASE_EASY_H
16 #include <type_traits>
18 /** Convenient for-loops using iterator.
20 * std::set<std::string>; _store;
21 * for_( it, _store.begin(), _store.end() )
23 * cout << *it << endl;
27 #ifndef __GXX_EXPERIMENTAL_CXX0X__
28 #define for_(IT,BEG,END) for ( __typeof__(BEG) IT = BEG, _for_end = END; IT != _for_end; ++IT )
30 #define for_(IT,BEG,END) for ( auto IT = BEG, _for_end = END; IT != _for_end; ++IT )
32 #define for_each_(IT,CONT) for_( IT, (CONT).begin(), (CONT).end() )
34 /** Simple C-array iterator
36 * const char * defstrings[] = { "", "a", "default", "two words" };
37 * for_( it, arrayBegin(defstrings), arrayEnd(defstrings) )
38 * cout << *it << endl;
41 #define arrayBegin(A) (&A[0])
42 #define arraySize(A) (sizeof(A)/sizeof(*A))
43 #define arrayEnd(A) (&A[0] + arraySize(A))
47 * defConstStr( strANY(), "ANY" );
48 * std::str str = strANY();
51 #define defConstStr(FNC,STR) inline const std::string & FNC { static const std::string val( STR ); return val; }
53 #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
54 #if GCC_VERSION < 40600 || not defined(__GXX_EXPERIMENTAL_CXX0X__)
58 /** Delete copy ctor and copy assign */
59 #define NON_COPYABLE(CLASS) \
60 CLASS( const CLASS & ) = delete; \
61 CLASS & operator=( const CLASS & ) = delete
63 /** Default copy ctor and copy assign */
64 #define DEFAULT_COPYABLE(CLASS) \
65 CLASS( const CLASS & ) = default; \
66 CLASS & operator=( const CLASS & ) = default
68 #ifndef SWIG // Swig treats it as syntax error
69 /** Delete move ctor and move assign */
70 #define NON_MOVABLE(CLASS) \
71 CLASS( CLASS && ) = delete; \
72 CLASS & operator=( CLASS && ) = delete
74 /** Default move ctor and move assign */
75 #define DEFAULT_MOVABLE(CLASS) \
76 CLASS( CLASS && ) = default; \
77 CLASS & operator=( CLASS && ) = default
79 #define NON_MOVABLE(CLASS)
80 #define DEFAULT_MOVABLE(CLASS)
83 /** Delete copy ctor and copy assign but enable default move */
84 #define NON_COPYABLE_BUT_MOVE( CLASS ) \
85 NON_COPYABLE(CLASS); \
86 DEFAULT_MOVABLE(CLASS)
88 /** Default move ctor and move assign but enable default copy */
89 #define NON_MOVABLE_BUT_COPY( CLASS ) \
91 DEFAULT_COPYABLE(CLASS)
94 /** Prevent an universal ctor to be chosen as copy ctor.
98 * template<typename TARG, typename X = disable_use_as_copy_ctor<FeedStrings,TARG>>
99 * FeedStrings( TARG && arg_r )
100 * : _value { std::forward<TARG>( arg_r ) }
103 * // Same with variadic template. Could be chosen as copy_ctor.
104 * template<typename ... Us>
105 * FeedStrings( Us &&... us )
109 * std::string _value;
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;
115 ///////////////////////////////////////////////////////////////////
117 { /////////////////////////////////////////////////////////////////
118 /////////////////////////////////////////////////////////////////
120 ///////////////////////////////////////////////////////////////////
121 #endif // ZYPP_BASE_EASY_H