isl_test_cpp17-generic.cc: work around std::optional::value issue in older macOS
[isl.git] / isl_multi_apply_templ.c
blob9eecfbcc3ed1d5014d6ae742c1ecb7b2247b500b
1 /*
2 * Copyright 2011 Sven Verdoolaege
3 * Copyright 2012-2013 Ecole Normale Superieure
5 * Use of this software is governed by the MIT license
7 * Written by Sven Verdoolaege,
8 * Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
9 */
11 #include <isl_multi_macro.h>
13 /* Transform the elements of "multi" by applying "fn" to them
14 * with extra argument "set".
15 * If "multi" has an explicit domain, then apply "fn_domain" or
16 * "fn_params" to this explicit domain instead.
17 * In particular, if the explicit domain is a parameter set,
18 * then apply "fn_params". Otherwise, apply "fn_domain".
20 static __isl_give MULTI(BASE) *FN(FN(MULTI(BASE),apply),APPLY_DOMBASE)(
21 __isl_take MULTI(BASE) *multi, __isl_take APPLY_DOM *set,
22 __isl_give EL *(*fn)(EL *el, __isl_take APPLY_DOM *set),
23 __isl_give DOM *(*fn_domain)(DOM *domain, __isl_take APPLY_DOM *set),
24 __isl_give DOM *(*fn_params)(DOM *domain, __isl_take APPLY_DOM *set))
26 isl_size n;
27 int i;
29 FN(FN(MULTI(BASE),align_params),APPLY_DOMBASE)(&multi, &set);
31 if (FN(MULTI(BASE),has_explicit_domain)(multi))
32 return FN(FN(MULTI(BASE),apply_domain),APPLY_DOMBASE)(multi,
33 set, fn_domain, fn_params);
35 n = FN(MULTI(BASE),size)(multi);
36 if (n < 0 || !set)
37 goto error;
39 for (i = 0; i < n; ++i) {
40 EL *el;
42 el = FN(MULTI(BASE),take_at)(multi, i);
43 el = fn(el, FN(APPLY_DOM,copy)(set));
44 multi = FN(MULTI(BASE),restore_at)(multi, i, el);
47 FN(APPLY_DOM,free)(set);
48 return multi;
49 error:
50 FN(APPLY_DOM,free)(set);
51 FN(MULTI(BASE),free)(multi);
52 return NULL;