Extracting function template parameters from template argument types

I'm currently trying to write a function that takes an STL array of any type as one of its parameters. The obvious way to write:

template<typename T, int count>
void setArrayBufferData(GLenum usage, const std::array<T, count>& data) {
  setArrayBufferData(usage, data.data(), sizeof(T) * count);
}

And here is another overload that it calls for reference only

void setArrayBufferData(GLenum usage, void* data, int size) {
  glBufferData(GL_ARRAY_BUFFER, size, data, usage);
}

Function definition compiles fine. However, when I try to call it

std::array<int, 4> data;
setArrayBufferData(GL_STATIC_DRAW, data);

" setArrayBufferData". , , , , . , , std:: array, , , , , . , , ?

+5
1
template<typename T, int count>
void setArrayBufferData(GLenum usage, const std::array<T, count>& data)

, std:: array - template<typename T, size_t N> struct array. size_t, int.

, data.data() const T *, const std:: array, setArrayBufferData(GLenum usage, const void* data, int size) setArrayBufferData(usage, const_cast<T*>(data.data()), sizeof(T) * count);

#include <array>

void function(const void* ptr, size_t bytes)
{
}

template<typename T, size_t count>
void function(const std::array<T, count>& array)
{
   function(array.data(), sizeof(T) * count);
}

int main()
{
   std::array<int, 4> array;
   function(array);
}

. http://liveworkspace.org/code/2a5af492e1f4229afdd0224171854d1c

+7

All Articles