1 //===-- main.cpp -------------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include <functional>
10 #include <stdlib.h>
11 
12 template<typename ElemType>
13 ElemType* alloc(size_t count, std::function<ElemType(size_t)> get)
14 {
15   ElemType *elems = new ElemType[count];
16   for(size_t i = 0; i < count; i++)
17     elems[i] = get(i);
18   return elems;
19 }
20 
21 int main (int argc, const char * argv[])
22 {
23   int* data = alloc<int>(5, [] (size_t idx) -> int {
24     return 2 * idx + 1;
25   });
26   return 0; // break here
27 }
28 
29