// // MIT License // Copyright (c) 2020 Jonathan R. Madsen // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // #pragma once #ifndef FALSE # define FALSE 0 #endif #ifndef TRUE # define TRUE 1 #endif #include // Retrieve definitions of min/max // Include base types #include "PTL/Types.hh" // Global utility functions #include "PTL/Utility.hh" #include #include #include #include #if !defined(PTL_FOLD_EXPRESSION) # define PTL_FOLD_EXPRESSION(...) \ ::PTL::mpl::consume_parameters( \ ::std::initializer_list{ (__VA_ARGS__, 0)... }) #endif namespace PTL { template using decay_t = typename std::decay::type; template using enable_if_t = typename std::enable_if::type; // for pre-C++14 tuple expansion to arguments namespace mpl { //--------------------------------------------------------------------------------------// template void consume_parameters(Args&&...) {} //--------------------------------------------------------------------------------------// namespace impl { //--------------------------------------------------------------------------------------// // Stores a tuple of indices. Used by tuple and pair, and by bind() to // extract the elements in a tuple. template struct Index_tuple {}; // Concatenates two Index_tuples. template struct Itup_cat; template struct Itup_cat, Index_tuple> { using __type = Index_tuple; }; // Builds an Index_tuple<0, 1, 2, ..., NumT-1>. template struct Build_index_tuple : Itup_cat::__type, typename Build_index_tuple::__type> {}; template <> struct Build_index_tuple<1> { typedef Index_tuple<0> __type; }; template <> struct Build_index_tuple<0> { typedef Index_tuple<> __type; }; /// Class template integer_sequence template struct integer_sequence { typedef Tp value_type; static constexpr size_t size() noexcept { return sizeof...(Idx); } }; template ::__type> struct Make_integer_sequence; template struct Make_integer_sequence> { static_assert(NumT >= 0, "Cannot make integer sequence of negative length"); typedef integer_sequence(Idx)...> __type; }; /// Alias template make_integer_sequence template using make_integer_sequence = typename Make_integer_sequence::__type; /// Alias template index_sequence template using index_sequence = integer_sequence; /// Alias template make_index_sequence template using make_index_sequence = make_integer_sequence; /// Alias template index_sequence_for template using index_sequence_for = make_index_sequence; template using index_type_t = decay_t(std::declval()))>; template static inline auto apply(FnT&& __f, TupleT&& __t, impl::index_sequence) -> decltype(std::forward(__f)(std::get(__t)...)) { return std::forward(__f)(std::get(__t)...); } //--------------------------------------------------------------------------------------// } // namespace impl //--------------------------------------------------------------------------------------// /// Alias template index_sequence template using index_sequence = impl::integer_sequence; /// Alias template make_index_sequence template using make_index_sequence = impl::make_integer_sequence; /// Alias template index_sequence_for template using index_sequence_for = impl::make_index_sequence; template static inline void apply(FnT&& __f, TupleT&& __t) { constexpr auto N = std::tuple_size::value; impl::apply(std::forward(__f), std::forward(__t), impl::make_index_sequence{}); } //--------------------------------------------------------------------------------------// } // namespace mpl namespace thread_pool { namespace state { static const short STARTED = 0; static const short PARTIAL = 1; static const short STOPPED = 2; static const short NONINIT = 3; } // namespace state } // namespace thread_pool //--------------------------------------------------------------------------------------// } // namespace PTL