C++ Logo

std-proposals

Advanced search

fixed type parameter packs

From: Dominic Fandrey <isocpp.id_at_[hidden]>
Date: Tue, 11 Aug 2020 12:44:48 +0200
There is another feature I've been wondering why it doesn't exist.
I'll show this by example:

template <std::string_view ... Ts>
constexpr std::string concat(Ts ... strs) {
 using std::cend;
 using std::cbegin;
 std::string result;
 result.reserve(strs.size() + ...);
 return (result.insert(cend(result), cbegin(strs), cend(strs)), ...);
}

An alternative use case:

constexpr <typename T>
constexpr T min(T const & val) {
 return val;
}

template <typename T, T .. Ts>
constexpr T min(T const & lhs, Ts const & ... tail) {
 auto const rhs = min<T>(tail ...);
 return lhs < rhs ? lhs : rhs;
}

This would allow explicitly giving a T for a whole parameter pack.

Received on 2020-08-11 05:48:13