#include <cstddef>
#include <iostream>
#include <algorithm>
#include <string>
template <typename iter>
void print(iter begin, iter end, const std::string& separator = " ", const std::string& terminator = "\n", std::ostream& os = std::cout)
{
while (begin != end)
{
os << *begin++ ;
if (begin != end)
os << separator;
}
os << terminator;
}
void myreverse(int* beg, int* end)
{
using std::swap;
if (beg && end && beg < --end)
while (beg < end)
swap(*beg++, *end--);
}
int main()
{
const std::size_t size = 5;
int arr[size] = { 1, 2, 3, 4, 5 };
int* arr_beg = arr;
int* arr_end = arr + size;
print(arr_beg, arr_end, ", ");
std::reverse(arr_beg, arr_end);
print(arr_beg, arr_end, ", ");
myreverse(arr_beg, arr_end);
print(arr_beg, arr_end, ", ");
}
I2luY2x1ZGUgPGNzdGRkZWY+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPHN0cmluZz4KCnRlbXBsYXRlIDx0eXBlbmFtZSBpdGVyPgp2b2lkIHByaW50KGl0ZXIgYmVnaW4sIGl0ZXIgZW5kLCBjb25zdCBzdGQ6OnN0cmluZyYgc2VwYXJhdG9yID0gIiAiLCBjb25zdCBzdGQ6OnN0cmluZyYgdGVybWluYXRvciA9ICJcbiIsIHN0ZDo6b3N0cmVhbSYgb3MgPSBzdGQ6OmNvdXQpCnsKICAgIHdoaWxlIChiZWdpbiAhPSBlbmQpCiAgICB7CiAgICAgICAgb3MgPDwgKmJlZ2luKysgOwoKICAgICAgICBpZiAoYmVnaW4gIT0gZW5kKQogICAgICAgICAgICBvcyA8PCBzZXBhcmF0b3I7CiAgICB9CgogICAgb3MgPDwgdGVybWluYXRvcjsKfQoKdm9pZCBteXJldmVyc2UoaW50KiBiZWcsIGludCogZW5kKQp7CiAgICB1c2luZyBzdGQ6OnN3YXA7CgogICAgaWYgKGJlZyAmJiBlbmQgJiYgYmVnIDwgLS1lbmQpCiAgICAgICAgd2hpbGUgKGJlZyA8IGVuZCkKICAgICAgICAgICAgc3dhcCgqYmVnKy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