Created
February 23, 2022 06:16
-
-
Save buffyanamin/406002d5dda51040531ff379ca33e08b to your computer and use it in GitHub Desktop.
c++ template specify type after variadic types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// from https://www.cppstories.com/2020/09/variadic-pack-first.html/ | |
namespace detail | |
{ | |
template<typename Output, typename... Inputs> | |
void tempFunc(Output& output, Inputs const&... inputs) | |
{ | |
// implementation of f | |
} | |
template<typename... InputsThenOutput, size_t... InputIndexes> | |
void tempFunc(std::tuple<InputsThenOutput...> inputsThenOutputs, std::index_sequence<InputIndexes...>) | |
{ | |
auto constexpr OutputIndex = sizeof...(InputsThenOutput) - 1; | |
detail::tempFunc(std::get<OutputIndex>(inputsThenOutputs), std::get<InputIndexes>(inputsThenOutputs)...); | |
} | |
} | |
// usage: tempFunc(input1, input2, input3, output); | |
template<typename... InputsThenOutput> | |
void tempFunc(InputsThenOutput&&... inputsThenOutput) | |
{ | |
detail::tempFunc(std::forward_as_tuple(inputsThenOutput...), std::make_index_sequence<sizeof...(inputsThenOutput) - 1>{}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment