1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/base/TypeTraits.h
11 #ifndef ZYPP_TYPETRAITS_H
12 #define ZYPP_TYPETRAITS_H
14 #include <type_traits>
16 ///////////////////////////////////////////////////////////////////
19 ///////////////////////////////////////////////////////////////////
22 template<typename _Tp>
23 struct _has_type_const_iterator
26 template<typename C> static std::true_type test( typename C::const_iterator * );
27 template<typename C> static std::false_type test(...);
29 static constexpr bool value = decltype(test<_Tp>(nullptr))::value;
32 template <typename _Tp>
33 struct _has_container_begin_end
37 using Signature = typename C::const_iterator(C::*)() const;
39 template<typename C> static std::true_type testBeg( typename std::enable_if<std::is_same<decltype(static_cast<Signature<C>>(&C::begin)), Signature<C>>::value, void>::type* );
40 template<typename C> static std::false_type testBeg(...);
42 template<typename C> static std::true_type testEnd( typename std::enable_if<std::is_same<decltype(static_cast<Signature<C>>(&C::end)), Signature<C>>::value, void>::type* );
43 template<typename C> static std::false_type testEnd(...);
46 static constexpr bool beg_value = decltype(testBeg<_Tp>(nullptr))::value;
47 static constexpr bool end_value = decltype(testEnd<_Tp>(nullptr))::value;
48 static constexpr bool value = beg_value && end_value;
50 } // namespace _detail
51 ///////////////////////////////////////////////////////////////////
53 /** Whether \a _Tp defines type \a _Tp::const_iterator */
54 template<typename _Tp>
55 struct has_type_const_iterator
56 : public std::integral_constant<bool, _detail::has_type_const_iterator<_Tp>::value>
59 /** Whether \a _Tp defines methods <tt>_Tp::const_iterator begin/end() const</tt> */
60 template<typename _Tp>
61 struct has_container_begin_end
62 : public std::integral_constant<bool, _detail::_has_container_begin_end<_Tp>::value>
65 /** Whether \a _Tp is a container (begin/end iterabel, but not plain std::string) */
66 template<typename _Tp>
68 : public std::integral_constant<bool, !std::is_same<_Tp, std::string>::value && has_container_begin_end<_Tp>::value>
73 ///////////////////////////////////////////////////////////////////
74 #endif // ZYPP_TYPETRAITS_H