#include <cstddef>
#include <initializer_list>
template < std:: size_t ...>
struct indices { } ;
template < std:: size_t N, std:: size_t ... Indices >
struct make_indices:
make_indices< N- 1 , N- 1 , Indices...>
{ } ;
template < std:: size_t ... Indices >
struct make_indices< 0 , Indices...> :
indices< Indices...>
{ } ;
template < typename T>
struct array:
public std:: initializer_list < T>
{
constexpr array( std:: initializer_list < T> values) :
std:: initializer_list < T> ( values)
{ }
constexpr auto operator[ ] ( std:: size_t n)
- > T
{
return this- > begin( ) [ n] ;
}
} ;
template < typename T, std:: size_t ... I >
auto constexpr add_one( const array< T> & a, indices< I...> )
- > const array< T>
{
return { ( a[ I] + 1 ) ... } ;
}
int main( )
{
constexpr array< int > a = { 1 , 2 , 3 } ;
constexpr auto b = add_one( a, make_indices< a.size ( ) > ( ) ) ;
return 0 ;
}
I2luY2x1ZGUgPGNzdGRkZWY+CiNpbmNsdWRlIDxpbml0aWFsaXplcl9saXN0PgoKdGVtcGxhdGU8c3RkOjpzaXplX3QuLi4+CnN0cnVjdCBpbmRpY2VzIHt9OwogCnRlbXBsYXRlPHN0ZDo6c2l6ZV90IE4sIHN0ZDo6c2l6ZV90Li4uIEluZGljZXM+CnN0cnVjdCBtYWtlX2luZGljZXM6CiAgICBtYWtlX2luZGljZXM8Ti0xLCBOLTEsIEluZGljZXMuLi4+Cnt9OwogCnRlbXBsYXRlPHN0ZDo6c2l6ZV90Li4uIEluZGljZXM+CnN0cnVjdCBtYWtlX2luZGljZXM8MCwgSW5kaWNlcy4uLj46CiAgICBpbmRpY2VzPEluZGljZXMuLi4+Cnt9OwogCnRlbXBsYXRlPHR5cGVuYW1lIFQ+CnN0cnVjdCBhcnJheToKICAgIHB1YmxpYyBzdGQ6OmluaXRpYWxpemVyX2xpc3Q8VD4KewogICAgY29uc3RleHByIGFycmF5KHN0ZDo6aW5pdGlhbGl6ZXJfbGlzdDxUPiB2YWx1ZXMpOgogICAgICAgIHN0ZDo6aW5pdGlhbGl6ZXJfbGlzdDxUPih2YWx1ZXMpCiAgICB7fQogCiAgICBjb25zdGV4cHIgYXV0byBvcGVyYXRvcltdKHN0ZDo6c2l6ZV90IG4pCiAgICAgICAgLT4gVAogICAgewogICAgICAgIHJldHVybiB0aGlzLT5iZWdpbigpW25dOwogICAgfQp9OwogCnRlbXBsYXRlPHR5cGVuYW1lIFQsIHN0ZDo6c2l6ZV90Li4uIEk+CmF1dG8gY29uc3RleHByIGFkZF9vbmUoY29uc3QgYXJyYXk8VD4mIGEsIGluZGljZXM8SS4uLj4pCiAgICAtPiBjb25zdCBhcnJheTxUPgp7CiAgICByZXR1cm4geyAoYVtJXSsxKS4uLiB9Owp9CiAKaW50IG1haW4oKQp7CiAgICBjb25zdGV4cHIgYXJyYXk8aW50PiBhID0geyAxLCAyLCAzIH07CiAgICBjb25zdGV4cHIgYXV0byBiID0gYWRkX29uZShhLCBtYWtlX2luZGljZXM8YS5zaXplKCk+KCkpOwogCiAgICByZXR1cm4gMDsKfQ==
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:42:59: error: ‘const array<int>{std::initializer_list<int>{((const int*)(& const int [3]{2, 3, 4})), 3u}}’ is not a constant expression
stdout