#include <iostream>
#include <array>
template <std::size_t... Idx>
using list = std::index_sequence<Idx...> *;
template <std::size_t Count>
using make_indices = std::make_index_sequence<Count> *;
template <class T>
constexpr void swap(T& a, T& b) noexcept {
T t = a;
a = b;
b = t;
}
template <class T, std::size_t N>
constexpr std::size_t partition(std::array<T, N> &array, std::size_t low, std::size_t high) noexcept {
auto pivot = array[high];
std::size_t i = low;
for (std::size_t j = low; j < high; ++j) {
if (array[j] <= pivot) {
swap(array[i], array[j]);
++i;
}
}
swap(array[i], array[high]);
return i;
}
template<class T, std::size_t N>
constexpr void sort(std::array<T, N>& array, std::size_t low = 0, std::size_t high = N-1) noexcept {
if (low < high && high != ~std::size_t(0)) {
std::size_t p = partition(array, low, high);
sort(array, low, p-1);
sort(array, p+1, high);
}
}
int main() {
std::array<int, 4> a = {3,2,4,1};
sort(a);
for(int i:a){
std::cout << i;
}
std::array<int, a[3]> b;
// your code goes here
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YXJyYXk+Cgp0ZW1wbGF0ZSA8c3RkOjpzaXplX3QuLi4gSWR4Pgp1c2luZyBsaXN0ID0gc3RkOjppbmRleF9zZXF1ZW5jZTxJZHguLi4+ICo7Cgp0ZW1wbGF0ZSA8c3RkOjpzaXplX3QgQ291bnQ+CnVzaW5nIG1ha2VfaW5kaWNlcyA9IHN0ZDo6bWFrZV9pbmRleF9zZXF1ZW5jZTxDb3VudD4gKjsKCnRlbXBsYXRlIDxjbGFzcyBUPgogIGNvbnN0ZXhwciB2b2lkIHN3YXAoVCYgYSwgVCYgYikgbm9leGNlcHQgewogICAgVCB0ID0gYTsKICAgIGEgPSBiOwogICAgYiA9IHQ7CiAgfQoKICB0ZW1wbGF0ZSA8Y2xhc3MgVCwgc3RkOjpzaXplX3QgTj4KICBjb25zdGV4cHIgc3RkOjpzaXplX3QgcGFydGl0aW9uKHN0ZDo6YXJyYXk8VCwgTj4gJmFycmF5LCBzdGQ6OnNpemVfdCBsb3csIHN0ZDo6c2l6ZV90IGhpZ2gpIG5vZXhjZXB0IHsKICAgIGF1dG8gcGl2b3QgPSBhcnJheVtoaWdoXTsKICAgIHN0ZDo6c2l6ZV90IGkgPSBsb3c7CiAgICBmb3IgKHN0ZDo6c2l6ZV90IGogPSBsb3c7IGogPCBoaWdoOyArK2opIHsKICAgICAgaWYgKGFycmF5W2pdIDw9IHBpdm90KSB7CiAgICAgICAgc3dhcChhcnJheVtpXSwgYXJyYXlbal0pOwogICAgICAgICsraTsKICAgICAgfQogICAgfQogICAgc3dhcChhcnJheVtpXSwgYXJyYXlbaGlnaF0pOwogICAgcmV0dXJuIGk7CiAgfQoKICB0ZW1wbGF0ZTxjbGFzcyBULCBzdGQ6OnNpemVfdCBOPgogIGNvbnN0ZXhwciB2b2lkIHNvcnQoc3RkOjphcnJheTxULCBOPiYgYXJyYXksIHN0ZDo6c2l6ZV90IGxvdyA9IDAsIHN0ZDo6c2l6ZV90IGhpZ2ggPSBOLTEpIG5vZXhjZXB0IHsKICAgIGlmIChsb3cgPCBoaWdoICYmIGhpZ2ggIT0gfnN0ZDo6c2l6ZV90KDApKSB7CiAgICAgIHN0ZDo6c2l6ZV90IHAgPSBwYXJ0aXRpb24oYXJyYXksIGxvdywgaGlnaCk7CiAgICAgIHNvcnQoYXJyYXksIGxvdywgcC0xKTsKICAgICAgc29ydChhcnJheSwgcCsxLCBoaWdoKTsKICAgIH0KICB9CgoKaW50IG1haW4oKSB7CglzdGQ6OmFycmF5PGludCwgND4gYSA9IHszLDIsNCwxfTsKCXNvcnQoYSk7Cglmb3IoaW50IGk6YSl7CgkJc3RkOjpjb3V0IDw8IGk7Cgl9CglzdGQ6OmFycmF5PGludCwgYVszXT4gYjsKCQoJLy8geW91ciBjb2RlIGdvZXMgaGVyZQoJcmV0dXJuIDA7Cn0=
prog.cpp: In function ‘int main()’:
prog.cpp:47:21: error: call to non-‘constexpr’ function ‘std::array<_Tp, _Nm>::value_type& std::array<_Tp, _Nm>::operator[](std::array<_Tp, _Nm>::size_type) [with _Tp = int; long unsigned int _Nm = 4; std::array<_Tp, _Nm>::reference = int&; std::array<_Tp, _Nm>::value_type = int; std::array<_Tp, _Nm>::size_type = long unsigned int]’
std::array<int, a[3]> b;
^
prog.cpp:47:21: error: call to non-‘constexpr’ function ‘std::array<_Tp, _Nm>::value_type& std::array<_Tp, _Nm>::operator[](std::array<_Tp, _Nm>::size_type) [with _Tp = int; long unsigned int _Nm = 4; std::array<_Tp, _Nm>::reference = int&; std::array<_Tp, _Nm>::value_type = int; std::array<_Tp, _Nm>::size_type = long unsigned int]’
prog.cpp:47:22: note: in template argument for type ‘long unsigned int’
std::array<int, a[3]> b;
^