struct Platform
{
cl_platform_id operator*() { return platform; }
// no virtuals, no other data
protected:
cl_platform_id platform;
};
std::vector<Platform> getPlatforms()
{
vector<Platform> platforms;
cl_uint n_platforms;
clGetPlatformIDs(0, 0, &n_platforms);
platforms.reserve(n_platforms);
clGetPlatformIDs(n_platforms, reinterpret_cast<cl_platform_id*>(&platforms.front()), 0);
return platforms;
}
This code fills vector platforms with n_platforms elements.
The only harmful until now, is that this code doesn't set the vector's size.
With this approach I avoid to create an intermediate array and then copy array data to vector.