brintos

brintos / llvm-project-archived public Read only

0
0
Text · 414 B · 63001eb Raw
21 lines · cpp
1#include <functional>2#include <stdlib.h>3 4template<typename ElemType>5ElemType* alloc(size_t count, std::function<ElemType(size_t)> get)6{7  ElemType *elems = new ElemType[count];8  for(size_t i = 0; i < count; i++)9    elems[i] = get(i);10  return elems;11}12 13int main (int argc, const char * argv[])14{15  int* data = alloc<int>(5, [] (size_t idx) -> int {16    return 2 * idx + 1;17  });18  return 0; // break here19}20 21