Date: Wed, 22 May 2024 14:51:20 +0300
On Wed, 22 May 2024 at 14:25, Rhidian De Wit via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> How would the compiler, and the user, figure out where the parameter pack ends, and the next template parameter pack starts?
It already does, with the rule that the non-terminal pack must be
provided, and anything after it must be deduced. The suggestion
breaks code that relies on that rule.
Thus:
https://wandbox.org/permlink/hoBATXKR3zOlj5t7
#include <string>
#include <tuple>
#include <type_traits>
template<typename... A, typename... B>
std::tuple<std::tuple<std::remove_reference_t<A>...>,
std::tuple<std::remove_reference_t<B>...>>
f(A&&... a, B&&... b)
{
return std::make_tuple(std::make_tuple(a...), std::make_tuple(b...));
}
int main()
{
auto a = f<int, int, int>(1, 2, 3, std::string("oh"),
std::string("em"), std::string("gee"));
static_assert(std::is_same_v<decltype(a),
std::tuple<
std::tuple<int, int, int>,
std::tuple<std::string, std::string, std::string>>>);
auto b = f<std::string, std::string,
std::string>(std::string("oh"), std::string("em"), std::string("gee"),
1, 2, 3);
static_assert(std::is_same_v<decltype(b),
std::tuple<
std::tuple<std::string, std::string, std::string>,
std::tuple<int, int, int>>>);
}
<std-proposals_at_[hidden]> wrote:
>
> How would the compiler, and the user, figure out where the parameter pack ends, and the next template parameter pack starts?
It already does, with the rule that the non-terminal pack must be
provided, and anything after it must be deduced. The suggestion
breaks code that relies on that rule.
Thus:
https://wandbox.org/permlink/hoBATXKR3zOlj5t7
#include <string>
#include <tuple>
#include <type_traits>
template<typename... A, typename... B>
std::tuple<std::tuple<std::remove_reference_t<A>...>,
std::tuple<std::remove_reference_t<B>...>>
f(A&&... a, B&&... b)
{
return std::make_tuple(std::make_tuple(a...), std::make_tuple(b...));
}
int main()
{
auto a = f<int, int, int>(1, 2, 3, std::string("oh"),
std::string("em"), std::string("gee"));
static_assert(std::is_same_v<decltype(a),
std::tuple<
std::tuple<int, int, int>,
std::tuple<std::string, std::string, std::string>>>);
auto b = f<std::string, std::string,
std::string>(std::string("oh"), std::string("em"), std::string("gee"),
1, 2, 3);
static_assert(std::is_same_v<decltype(b),
std::tuple<
std::tuple<std::string, std::string, std::string>,
std::tuple<int, int, int>>>);
}
Received on 2024-05-22 11:51:35