#include <iostream>
using namespace std;
template <int Size, typename T>
int getArrayLength(T (&s)[Size]) {
return Size;
}
template<int Size, typename T>
int getArrayLength(T* s) {
return Size;
}
int main() {
int a[100];
int* b = new int[50];
cout << getArrayLength(a) << endl; // 100 -- первая функция
cout << getArrayLength<20>(a) << endl; // 20 -- вторая функция
cout << getArrayLength<50>(b) << endl; // 50 -- вторая функция
cout << getArrayLength<100>(a) << endl; // ошибка -- муки выбора
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnRlbXBsYXRlIDxpbnQgU2l6ZSwgdHlwZW5hbWUgVD4KaW50IGdldEFycmF5TGVuZ3RoKFQgKCZzKVtTaXplXSkgewoJcmV0dXJuIFNpemU7Cn0KCnRlbXBsYXRlPGludCBTaXplLCB0eXBlbmFtZSBUPgppbnQgZ2V0QXJyYXlMZW5ndGgoVCogcykgewoJcmV0dXJuIFNpemU7Cn0KCmludCBtYWluKCkgewoJaW50IGFbMTAwXTsKCWludCogYiA9IG5ldyBpbnRbNTBdOwoJCgljb3V0IDw8IGdldEFycmF5TGVuZ3RoKGEpIDw8IGVuZGw7IC8vIDEwMCAtLSDQv9C10YDQstCw0Y8g0YTRg9C90LrRhtC40Y8KCWNvdXQgPDwgZ2V0QXJyYXlMZW5ndGg8MjA+KGEpIDw8IGVuZGw7IC8vIDIwIC0tINCy0YLQvtGA0LDRjyDRhNGD0L3QutGG0LjRjwoJY291dCA8PCBnZXRBcnJheUxlbmd0aDw1MD4oYikgPDwgZW5kbDsgLy8gNTAgLS0g0LLRgtC+0YDQsNGPINGE0YPQvdC60YbQuNGPCgljb3V0IDw8IGdldEFycmF5TGVuZ3RoPDEwMD4oYSkgPDwgZW5kbDsgLy8g0L7RiNC40LHQutCwIC0tINC80YPQutC4INCy0YvQsdC+0YDQsAoJCglyZXR1cm4gMDsKfQo=