| 1 |
#include <array> |
| 2 |
#include <string> |
| 3 |
#include <vector> |
| 4 |
|
| 5 |
template<typename T> |
| 6 |
T& identity (T& v) { return v; } |
| 7 |
template<typename T> |
| 8 |
T** identityPP (T** v) { return v; } |
| 9 |
|
| 10 |
template<typename T> |
| 11 |
std::vector<T>* getVector(size_t len, const T* ptr) |
| 12 |
{ |
| 13 |
std::vector<T>* ret = new std::vector<T>(len); |
| 14 |
for (size_t i = 0; i < len; ++i) |
| 15 |
(*ret)[i] = ptr[i]; |
| 16 |
return ret; |
| 17 |
} |
| 18 |
|
| 19 |
std::string* getString(int len, const char* ptr) |
| 20 |
{ |
| 21 |
return new std::string(ptr, len); |
| 22 |
} |
| 23 |
|
| 24 |
template<typename T, size_t N> |
| 25 |
std::array<T, N>* getArray(const T* ptr) |
| 26 |
{ |
| 27 |
std::array<T, N>* ret = new std::array<T, N>(); |
| 28 |
for (size_t x = 0; x < N; ++x) |
| 29 |
(*ret)[x] = ptr[x]; |
| 30 |
return ret; |
| 31 |
} |
| 32 |
|
| 33 |
// Explicit instantiations, so they are callable outside this compilation unit. |
| 34 |
template int** identityPP<int>(int**); |
| 35 |
template float** identityPP<float>(float**); |
| 36 |
template int& identity<int>(int&); |
| 37 |
template float& identity<float>(float&); |
| 38 |
|
| 39 |
template std::vector<int>* getVector<int>(size_t, const int*); |
| 40 |
template std::vector<float>* getVector<float>(size_t, const float*); |
| 41 |
//typedef std::vector<float> svf_t; |
| 42 |
//template std::vector<svf_t>* getVector<svf_t>(size_t, const svf_t*); |
| 43 |
|
| 44 |
template std::array<int, 4>* getArray<int, 4>(const int*); |
| 45 |
template std::array<float, 4>* getArray<float, 4>(const float*); |
| 46 |
//typedef Foo<int, 42> fi42_t; |
| 47 |
//template std::array<fi42_t, 4> getArray<fi42_t, 4>(const fi42_t*); |