Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <iostream>
- #define USE_CPP
- #ifdef USE_CPP
- //CPP code
- template<typename T_Value>
- struct Span
- {
- template<int T_ArraySize>
- Span(T_Value (&_value)[T_ArraySize])
- {
- Pointer = &_value[0];
- Size = T_ArraySize;
- }
- Span(std::vector<T_Value>& _value)
- {
- Pointer = &_value[0];
- Size = _value.size();
- }
- int size() const { return Size; }
- T_Value operator[](int _Index) { return Pointer[_Index]; }
- public:
- T_Value* Pointer;
- int Size;
- };
- inline void CallFunctionThatTakesArrayWithAnySize(Span<int> _array)
- {
- for (int i = 0; i < _array.size(); ++i)
- {
- printf("%d", _array[i]);
- }
- }
- int main()
- {
- int AnArray[5];
- CallFunctionThatTakesArrayWithAnySize(AnArray);
- }
- #else
- //C code
- inline void CallFunctionThatTakesArrayWithAnySize(int* _array, int _arraysize)
- {
- for (int i = 0; i < _arraysize; ++i)
- {
- printf("%d", _array[i]);
- }
- }
- int main()
- {
- int AnArray[5];
- CallFunctionThatTakesArrayWithAnySize(AnArray, 5);
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement