// This file is part of OpenCV project. // It is subject to the license terms in the LICENSE file found in the top-level directory // of this distribution and at http://opencv.org/license.html. // // Copyright (C) 2018-2019 Intel Corporation #ifndef OPENCV_GAPI_UTIL_HPP #define OPENCV_GAPI_UTIL_HPP #include // \cond HIDDEN_SYMBOLS // This header file contains some generic utility functions which are // used in other G-API Public API headers. // // PLEASE don't put any stuff here if it is NOT used in public API headers! namespace cv { namespace detail { // Recursive integer sequence type, useful for enumerating elements of // template parameter packs. template struct Seq { using next = Seq; }; template struct MkSeq { using type = typename MkSeq::type::next; }; template<> struct MkSeq<0>{ using type = Seq<>; }; // Checks if elements of variadic template satisfy the given Predicate. // Implemented via tuple, with an interface to accept plain type lists template class, typename, typename...> struct all_satisfy; template class F, typename T, typename... Ts> struct all_satisfy > { static const constexpr bool value = F::value && all_satisfy >::value; }; template class F, typename T> struct all_satisfy > { static const constexpr bool value = F::value; }; template class F, typename T, typename... Ts> struct all_satisfy: public all_satisfy > {}; // Permute given tuple type C with given integer sequence II // Sequence may be less than tuple C size. template struct permute_tuple; template struct permute_tuple > { using type = std::tuple< typename std::tuple_element::type... >; }; // Given T..., generates a type sequence of sizeof...(T)-1 elements // which is T... without its last element // Implemented via tuple, with an interface to accept plain type lists template struct all_but_last; template struct all_but_last > { using C = std::tuple; using S = typename MkSeq::value - 1>::type; using type = typename permute_tuple::type; }; template struct all_but_last: public all_but_last > {}; template using all_but_last_t = typename all_but_last::type; // NB.: This is here because there's no constexpr std::max in C++11 template struct max_of_t { static constexpr const std::size_t rest = max_of_t::value; static constexpr const std::size_t value = rest > S0 ? rest : S0; }; template struct max_of_t { static constexpr const std::size_t value = S; }; template struct contains : std::false_type{}; template struct contains : std::integral_constant::value || contains::value> {}; template struct contains> : std::integral_constant::value> {}; template struct all_unique : std::true_type{}; template struct all_unique : std::integral_constant::value && all_unique::value> {}; template struct tuple_wrap_helper; template struct tuple_wrap_helper { using type = std::tuple; static type get(T&& obj) { return std::make_tuple(std::move(obj)); } }; template struct tuple_wrap_helper> { using type = std::tuple; static type get(std::tuple&& objs) { return std::forward>(objs); } }; template struct make_void { typedef void type;}; template using void_t = typename make_void::type; } // namespace detail namespace util { template struct overload_lamba_set; template struct overload_lamba_set : public L1 { overload_lamba_set(L1&& lambda) : L1(std::move(lambda)) {} overload_lamba_set(const L1& lambda) : L1(lambda) {} using L1::operator(); }; template struct overload_lamba_set : public L1, public overload_lamba_set { using base_type = overload_lamba_set; overload_lamba_set(L1 &&lambda1, L&& ...lambdas): L1(std::move(lambda1)), base_type(std::forward(lambdas)...) {} overload_lamba_set(const L1 &lambda1, L&& ...lambdas): L1(lambda1), base_type(std::forward(lambdas)...) {} using L1::operator(); using base_type::operator(); }; template overload_lamba_set overload_lambdas(L&& ...lambdas) { return overload_lamba_set(std::forward(lambdas)...); } template struct find_adapter_impl; template struct find_adapter_impl { using type = typename std::conditional::value, T, void>::type; static constexpr bool found = std::is_base_of::value; }; template struct find_adapter_impl { using type = typename std::conditional::value, T, typename find_adapter_impl::type>::type; static constexpr bool found = std::is_base_of::value || find_adapter_impl::found; }; } // namespace util } // namespace cv // \endcond #endif // OPENCV_GAPI_UTIL_HPP