#include <iostream>
template < size_t N, typename T >
struct param_packer : param_packer<N-1,T>
{
int value;
param_packer( param_packer<N-1,T> const & other,
int last )
: param_packer<N-1,T>(other), value(last)
{ }
param_packer<N+1,T>
operator,( T append ) const {
return param_packer<N+1,T>( *this, append );
}
};
template < typename T >
struct param_packer<0,T>
{
param_packer<1,T>
operator,( T first ) const {
return param_packer<1,T>( *this, first );
}
};
template < size_t I, size_t N, typename T >
T&
param_at( param_packer<N,T> & pack ) {
return static_cast< param_packer<I+1,T>* >(&pack)->value;
}
param_packer<0,int> _;
template < size_t N >
void foo( param_packer<N, int> pack ) {
std::cout << "N = " << N << std::endl;
std::cout << "\t param at <0> is: " << param_at<0>( pack ) << std::endl;
std::cout << "\t param at <N-1> is: " << param_at<N-1>( pack ) << std::endl;
}
int main() {
foo( (_, 1, 2) );
}
I2luY2x1ZGUgPGlvc3RyZWFtPgogCnRlbXBsYXRlIDwgc2l6ZV90IE4sIHR5cGVuYW1lIFQgPgpzdHJ1Y3QgcGFyYW1fcGFja2VyIDogcGFyYW1fcGFja2VyPE4tMSxUPgp7CiAgICBpbnQgdmFsdWU7CiAgICAKICAgIHBhcmFtX3BhY2tlciggcGFyYW1fcGFja2VyPE4tMSxUPiBjb25zdCAmIG90aGVyLCAKICAgICAgICAgICAgICAgICAgaW50IGxhc3QgKQogICAgOiBwYXJhbV9wYWNrZXI8Ti0xLFQ+KG90aGVyKSwgdmFsdWUobGFzdCkgCiAgICB7IH0KICAgIAogICAgcGFyYW1fcGFja2VyPE4rMSxUPgogICAgb3BlcmF0b3IsKCBUIGFwcGVuZCApIGNvbnN0IHsKICAgICAgICByZXR1cm4gcGFyYW1fcGFja2VyPE4rMSxUPiggKnRoaXMsIGFwcGVuZCApOwogICAgfQp9OwogCnRlbXBsYXRlIDwgdHlwZW5hbWUgVCA+CnN0cnVjdCBwYXJhbV9wYWNrZXI8MCxUPgp7CiAgICBwYXJhbV9wYWNrZXI8MSxUPgogICAgb3BlcmF0b3IsKCBUIGZpc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