// Copyright 2019 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_INTERNAL_TUPLE_H #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_INTERNAL_TUPLE_H #include "google/cloud/internal/invoke_result.h" #include "google/cloud/internal/utility.h" #include "google/cloud/version.h" #include namespace google { namespace cloud { inline namespace GOOGLE_CLOUD_CPP_NS { namespace internal { // This header re-implements some of C++14's header. /** * Extract the return type of `std::apply` for given argument types. */ template struct ApplyRes {}; /** * Extract the return type of `std::apply` for given argument types. */ template struct ApplyRes> { using type = typename invoke_result::type; }; /** * Implementation of `apply`. * * Inspired by the example in section 20.5.1 of the standard. * * @tparam F the functor to apply the tuple to * @tparam Tuple the tuple of arguments to apply to `F` * @tparam I indices 0..(sizeof(Tuple)-1) */ template typename ApplyRes::type>::type ApplyImpl( F&& f, Tuple&& t, index_sequence) { return std::forward(f)(std::get(std::forward(t))...); } // Re-implementation of `std::apply` from C++14 template typename ApplyRes::type>::type apply(F&& f, Tuple&& t) { using Indices = make_index_sequence< std::tuple_size::type>::value>; return ApplyImpl(std::forward(f), std::forward(t), Indices()); } } // namespace internal } // namespace GOOGLE_CLOUD_CPP_NS } // namespace cloud } // namespace google #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_INTERNAL_TUPLE_H