github.com/kaydxh/golang@v0.0.131/pkg/gocv/cgo/third_path/opencv4/include/opencv2/gapi/util/util.hpp (about) 1 // This file is part of OpenCV project. 2 // It is subject to the license terms in the LICENSE file found in the top-level directory 3 // of this distribution and at http://opencv.org/license.html. 4 // 5 // Copyright (C) 2018-2019 Intel Corporation 6 7 8 #ifndef OPENCV_GAPI_UTIL_HPP 9 #define OPENCV_GAPI_UTIL_HPP 10 11 #include <tuple> 12 13 // \cond HIDDEN_SYMBOLS 14 // This header file contains some generic utility functions which are 15 // used in other G-API Public API headers. 16 // 17 // PLEASE don't put any stuff here if it is NOT used in public API headers! 18 19 namespace cv 20 { 21 namespace detail 22 { 23 // Recursive integer sequence type, useful for enumerating elements of 24 // template parameter packs. 25 template<int... I> struct Seq { using next = Seq<I..., sizeof...(I)>; }; 26 template<int Sz> struct MkSeq { using type = typename MkSeq<Sz-1>::type::next; }; 27 template<> struct MkSeq<0>{ using type = Seq<>; }; 28 29 // Checks if elements of variadic template satisfy the given Predicate. 30 // Implemented via tuple, with an interface to accept plain type lists 31 template<template<class> class, typename, typename...> struct all_satisfy; 32 33 template<template<class> class F, typename T, typename... Ts> 34 struct all_satisfy<F, std::tuple<T, Ts...> > 35 { 36 static const constexpr bool value = F<T>::value 37 && all_satisfy<F, std::tuple<Ts...> >::value; 38 }; 39 template<template<class> class F, typename T> 40 struct all_satisfy<F, std::tuple<T> > 41 { 42 static const constexpr bool value = F<T>::value; 43 }; 44 45 template<template<class> class F, typename T, typename... Ts> 46 struct all_satisfy: public all_satisfy<F, std::tuple<T, Ts...> > {}; 47 48 // Permute given tuple type C with given integer sequence II 49 // Sequence may be less than tuple C size. 50 template<class, class> struct permute_tuple; 51 52 template<class C, int... IIs> 53 struct permute_tuple<C, Seq<IIs...> > 54 { 55 using type = std::tuple< typename std::tuple_element<IIs, C>::type... >; 56 }; 57 58 // Given T..., generates a type sequence of sizeof...(T)-1 elements 59 // which is T... without its last element 60 // Implemented via tuple, with an interface to accept plain type lists 61 template<typename T, typename... Ts> struct all_but_last; 62 63 template<typename T, typename... Ts> 64 struct all_but_last<std::tuple<T, Ts...> > 65 { 66 using C = std::tuple<T, Ts...>; 67 using S = typename MkSeq<std::tuple_size<C>::value - 1>::type; 68 using type = typename permute_tuple<C, S>::type; 69 }; 70 71 template<typename T, typename... Ts> 72 struct all_but_last: public all_but_last<std::tuple<T, Ts...> > {}; 73 74 template<typename... Ts> 75 using all_but_last_t = typename all_but_last<Ts...>::type; 76 77 // NB.: This is here because there's no constexpr std::max in C++11 78 template<std::size_t S0, std::size_t... SS> struct max_of_t 79 { 80 static constexpr const std::size_t rest = max_of_t<SS...>::value; 81 static constexpr const std::size_t value = rest > S0 ? rest : S0; 82 }; 83 template<std::size_t S> struct max_of_t<S> 84 { 85 static constexpr const std::size_t value = S; 86 }; 87 88 template <typename...> 89 struct contains : std::false_type{}; 90 91 template <typename T1, typename T2, typename... Ts> 92 struct contains<T1, T2, Ts...> : std::integral_constant<bool, std::is_same<T1, T2>::value || 93 contains<T1, Ts...>::value> {}; 94 template<typename T, typename... Types> 95 struct contains<T, std::tuple<Types...>> : std::integral_constant<bool, contains<T, Types...>::value> {}; 96 97 template <typename...> 98 struct all_unique : std::true_type{}; 99 100 template <typename T1, typename... Ts> 101 struct all_unique<T1, Ts...> : std::integral_constant<bool, !contains<T1, Ts...>::value && 102 all_unique<Ts...>::value> {}; 103 104 template<typename> 105 struct tuple_wrap_helper; 106 107 template<typename T> struct tuple_wrap_helper 108 { 109 using type = std::tuple<T>; 110 static type get(T&& obj) { return std::make_tuple(std::move(obj)); } 111 }; 112 113 template<typename... Objs> 114 struct tuple_wrap_helper<std::tuple<Objs...>> 115 { 116 using type = std::tuple<Objs...>; 117 static type get(std::tuple<Objs...>&& objs) { return std::forward<std::tuple<Objs...>>(objs); } 118 }; 119 } // namespace detail 120 } // namespace cv 121 122 // \endcond 123 124 #endif // OPENCV_GAPI_UTIL_HPP