Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:14:27

0001 // This file is part of Eigen, a lightweight C++ template library
0002 // for linear algebra.
0003 //
0004 // Copyright (C) 2013 Christian Seiler <christian@iwakd.de>
0005 //
0006 // This Source Code Form is subject to the terms of the Mozilla
0007 // Public License v. 2.0. If a copy of the MPL was not distributed
0008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
0009 
0010 #ifndef EIGEN_CXX11META_H
0011 #define EIGEN_CXX11META_H
0012 
0013 #include <vector>
0014 #include "EmulateArray.h"
0015 
0016 #include "CXX11Workarounds.h"
0017 
0018 namespace Eigen {
0019 
0020 namespace internal {
0021 
0022 /** \internal
0023   * \file CXX11/util/CXX11Meta.h
0024   * This file contains generic metaprogramming classes which are not specifically related to Eigen.
0025   * This file expands upon Core/util/Meta.h and adds support for C++11 specific features.
0026   */
0027 
0028 template<typename... tt>
0029 struct type_list { constexpr static int count = sizeof...(tt); };
0030 
0031 template<typename t, typename... tt>
0032 struct type_list<t, tt...> { constexpr static int count = sizeof...(tt) + 1; typedef t first_type; };
0033 
0034 template<typename T, T... nn>
0035 struct numeric_list { constexpr static std::size_t count = sizeof...(nn); };
0036 
0037 template<typename T, T n, T... nn>
0038 struct numeric_list<T, n, nn...> { static const std::size_t count = sizeof...(nn) + 1; const static T first_value = n; };
0039 
0040 #ifndef EIGEN_PARSED_BY_DOXYGEN
0041 /* numeric list constructors
0042  *
0043  * equivalencies:
0044  *     constructor                                              result
0045  *     typename gen_numeric_list<int, 5>::type                  numeric_list<int, 0,1,2,3,4>
0046  *     typename gen_numeric_list_reversed<int, 5>::type         numeric_list<int, 4,3,2,1,0>
0047  *     typename gen_numeric_list_swapped_pair<int, 5,1,2>::type numeric_list<int, 0,2,1,3,4>
0048  *     typename gen_numeric_list_repeated<int, 0, 5>::type      numeric_list<int, 0,0,0,0,0>
0049  */
0050 
0051 template<typename T, std::size_t n, T start = 0, T... ii> struct gen_numeric_list                     : gen_numeric_list<T, n-1, start, start + n-1, ii...> {};
0052 template<typename T, T start, T... ii>                    struct gen_numeric_list<T, 0, start, ii...> { typedef numeric_list<T, ii...> type; };
0053 
0054 template<typename T, std::size_t n, T start = 0, T... ii> struct gen_numeric_list_reversed                     : gen_numeric_list_reversed<T, n-1, start, ii..., start + n-1> {};
0055 template<typename T, T start, T... ii>                    struct gen_numeric_list_reversed<T, 0, start, ii...> { typedef numeric_list<T, ii...> type; };
0056 
0057 template<typename T, std::size_t n, T a, T b, T start = 0, T... ii> struct gen_numeric_list_swapped_pair                           : gen_numeric_list_swapped_pair<T, n-1, a, b, start, (start + n-1) == a ? b : ((start + n-1) == b ? a : (start + n-1)), ii...> {};
0058 template<typename T, T a, T b, T start, T... ii>                    struct gen_numeric_list_swapped_pair<T, 0, a, b, start, ii...> { typedef numeric_list<T, ii...> type; };
0059 
0060 template<typename T, std::size_t n, T V, T... nn> struct gen_numeric_list_repeated                 : gen_numeric_list_repeated<T, n-1, V, V, nn...> {};
0061 template<typename T, T V, T... nn>                struct gen_numeric_list_repeated<T, 0, V, nn...> { typedef numeric_list<T, nn...> type; };
0062 
0063 /* list manipulation: concatenate */
0064 
0065 template<class a, class b> struct concat;
0066 
0067 template<typename... as, typename... bs> struct concat<type_list<as...>,       type_list<bs...>>        { typedef type_list<as..., bs...> type; };
0068 template<typename T, T... as, T... bs>   struct concat<numeric_list<T, as...>, numeric_list<T, bs...> > { typedef numeric_list<T, as..., bs...> type; };
0069 
0070 template<typename... p> struct mconcat;
0071 template<typename a>                             struct mconcat<a>           { typedef a type; };
0072 template<typename a, typename b>                 struct mconcat<a, b>        : concat<a, b> {};
0073 template<typename a, typename b, typename... cs> struct mconcat<a, b, cs...> : concat<a, typename mconcat<b, cs...>::type> {};
0074 
0075 /* list manipulation: extract slices */
0076 
0077 template<int n, typename x> struct take;
0078 template<int n, typename a, typename... as> struct take<n, type_list<a, as...>> : concat<type_list<a>, typename take<n-1, type_list<as...>>::type> {};
0079 template<int n>                             struct take<n, type_list<>>         { typedef type_list<> type; };
0080 template<typename a, typename... as>        struct take<0, type_list<a, as...>> { typedef type_list<> type; };
0081 template<>                                  struct take<0, type_list<>>         { typedef type_list<> type; };
0082 
0083 template<typename T, int n, T a, T... as> struct take<n, numeric_list<T, a, as...>> : concat<numeric_list<T, a>, typename take<n-1, numeric_list<T, as...>>::type> {};
0084 template<typename T, int n>               struct take<n, numeric_list<T>>           { typedef numeric_list<T> type; };
0085 template<typename T, T a, T... as>        struct take<0, numeric_list<T, a, as...>> { typedef numeric_list<T> type; };
0086 template<typename T>                      struct take<0, numeric_list<T>>           { typedef numeric_list<T> type; };
0087 
0088 template<typename T, int n, T... ii>      struct h_skip_helper_numeric;
0089 template<typename T, int n, T i, T... ii> struct h_skip_helper_numeric<T, n, i, ii...> : h_skip_helper_numeric<T, n-1, ii...> {};
0090 template<typename T, T i, T... ii>        struct h_skip_helper_numeric<T, 0, i, ii...> { typedef numeric_list<T, i, ii...> type; };
0091 template<typename T, int n>               struct h_skip_helper_numeric<T, n>           { typedef numeric_list<T> type; };
0092 template<typename T>                      struct h_skip_helper_numeric<T, 0>           { typedef numeric_list<T> type; };
0093 
0094 template<int n, typename... tt>             struct h_skip_helper_type;
0095 template<int n, typename t, typename... tt> struct h_skip_helper_type<n, t, tt...> : h_skip_helper_type<n-1, tt...> {};
0096 template<typename t, typename... tt>        struct h_skip_helper_type<0, t, tt...> { typedef type_list<t, tt...> type; };
0097 template<int n>                             struct h_skip_helper_type<n>           { typedef type_list<> type; };
0098 template<>                                  struct h_skip_helper_type<0>           { typedef type_list<> type; };
0099 #endif //not EIGEN_PARSED_BY_DOXYGEN
0100 
0101 template<int n>
0102 struct h_skip {
0103   template<typename T, T... ii>
0104   constexpr static EIGEN_STRONG_INLINE typename h_skip_helper_numeric<T, n, ii...>::type helper(numeric_list<T, ii...>) { return typename h_skip_helper_numeric<T, n, ii...>::type(); }
0105   template<typename... tt>
0106   constexpr static EIGEN_STRONG_INLINE typename h_skip_helper_type<n, tt...>::type helper(type_list<tt...>) { return typename h_skip_helper_type<n, tt...>::type(); }
0107 };
0108 
0109 template<int n, typename a> struct skip { typedef decltype(h_skip<n>::helper(a())) type; };
0110 
0111 template<int start, int count, typename a> struct slice : take<count, typename skip<start, a>::type> {};
0112 
0113 /* list manipulation: retrieve single element from list */
0114 
0115 template<int n, typename x> struct get;
0116 
0117 template<int n, typename a, typename... as>               struct get<n, type_list<a, as...>>   : get<n-1, type_list<as...>> {};
0118 template<typename a, typename... as>                      struct get<0, type_list<a, as...>>   { typedef a type; };
0119 
0120 template<typename T, int n, T a, T... as>                        struct get<n, numeric_list<T, a, as...>>   : get<n-1, numeric_list<T, as...>> {};
0121 template<typename T, T a, T... as>                               struct get<0, numeric_list<T, a, as...>>   { constexpr static T value = a; };
0122 
0123 template<std::size_t n, typename T, T a, T... as> constexpr T       array_get(const numeric_list<T, a, as...>&) {
0124    return get<(int)n, numeric_list<T, a, as...>>::value;
0125 }
0126 
0127 /* always get type, regardless of dummy; good for parameter pack expansion */
0128 
0129 template<typename T, T dummy, typename t> struct id_numeric  { typedef t type; };
0130 template<typename dummy, typename t>      struct id_type     { typedef t type; };
0131 
0132 /* equality checking, flagged version */
0133 
0134 template<typename a, typename b> struct is_same_gf : is_same<a, b> { constexpr static int global_flags = 0; };
0135 
0136 /* apply_op to list */
0137 
0138 template<
0139   bool from_left, // false
0140   template<typename, typename> class op,
0141   typename additional_param,
0142   typename... values
0143 >
0144 struct h_apply_op_helper                                        { typedef type_list<typename op<values, additional_param>::type...> type; };
0145 template<
0146   template<typename, typename> class op,
0147   typename additional_param,
0148   typename... values
0149 >
0150 struct h_apply_op_helper<true, op, additional_param, values...> { typedef type_list<typename op<additional_param, values>::type...> type; };
0151 
0152 template<
0153   bool from_left,
0154   template<typename, typename> class op,
0155   typename additional_param
0156 >
0157 struct h_apply_op
0158 {
0159   template<typename... values>
0160   constexpr static typename h_apply_op_helper<from_left, op, additional_param, values...>::type helper(type_list<values...>)
0161   { return typename h_apply_op_helper<from_left, op, additional_param, values...>::type(); }
0162 };
0163 
0164 template<
0165   template<typename, typename> class op,
0166   typename additional_param,
0167   typename a
0168 >
0169 struct apply_op_from_left { typedef decltype(h_apply_op<true, op, additional_param>::helper(a())) type; };
0170 
0171 template<
0172   template<typename, typename> class op,
0173   typename additional_param,
0174   typename a
0175 >
0176 struct apply_op_from_right { typedef decltype(h_apply_op<false, op, additional_param>::helper(a())) type; };
0177 
0178 /* see if an element is in a list */
0179 
0180 template<
0181   template<typename, typename> class test,
0182   typename check_against,
0183   typename h_list,
0184   bool last_check_positive = false
0185 >
0186 struct contained_in_list;
0187 
0188 template<
0189   template<typename, typename> class test,
0190   typename check_against,
0191   typename h_list
0192 >
0193 struct contained_in_list<test, check_against, h_list, true>
0194 {
0195   constexpr static bool value = true;
0196 };
0197 
0198 template<
0199   template<typename, typename> class test,
0200   typename check_against,
0201   typename a,
0202   typename... as
0203 >
0204 struct contained_in_list<test, check_against, type_list<a, as...>, false> : contained_in_list<test, check_against, type_list<as...>, test<check_against, a>::value> {};
0205 
0206 template<
0207   template<typename, typename> class test,
0208   typename check_against
0209   EIGEN_TPL_PP_SPEC_HACK_DEFC(typename, empty)
0210 >
0211 struct contained_in_list<test, check_against, type_list<EIGEN_TPL_PP_SPEC_HACK_USE(empty)>, false> { constexpr static bool value = false; };
0212 
0213 /* see if an element is in a list and check for global flags */
0214 
0215 template<
0216   template<typename, typename> class test,
0217   typename check_against,
0218   typename h_list,
0219   int default_flags = 0,
0220   bool last_check_positive = false,
0221   int last_check_flags = default_flags
0222 >
0223 struct contained_in_list_gf;
0224 
0225 template<
0226   template<typename, typename> class test,
0227   typename check_against,
0228   typename h_list,
0229   int default_flags,
0230   int last_check_flags
0231 >
0232 struct contained_in_list_gf<test, check_against, h_list, default_flags, true, last_check_flags>
0233 {
0234   constexpr static bool value = true;
0235   constexpr static int global_flags = last_check_flags;
0236 };
0237 
0238 template<
0239   template<typename, typename> class test,
0240   typename check_against,
0241   typename a,
0242   typename... as,
0243   int default_flags,
0244   int last_check_flags
0245 >
0246 struct contained_in_list_gf<test, check_against, type_list<a, as...>, default_flags, false, last_check_flags> : contained_in_list_gf<test, check_against, type_list<as...>, default_flags, test<check_against, a>::value, test<check_against, a>::global_flags> {};
0247 
0248 template<
0249   template<typename, typename> class test,
0250   typename check_against
0251   EIGEN_TPL_PP_SPEC_HACK_DEFC(typename, empty),
0252   int default_flags,
0253   int last_check_flags
0254 >
0255 struct contained_in_list_gf<test, check_against, type_list<EIGEN_TPL_PP_SPEC_HACK_USE(empty)>, default_flags, false, last_check_flags> { constexpr static bool value = false; constexpr static int global_flags = default_flags; };
0256 
0257 /* generic reductions */
0258 
0259 template<
0260   typename Reducer,
0261   typename... Ts
0262 > struct reduce;
0263 
0264 template<
0265   typename Reducer
0266 > struct reduce<Reducer>
0267 {
0268   EIGEN_DEVICE_FUNC constexpr static EIGEN_STRONG_INLINE int run() { return Reducer::Identity; }
0269 };
0270 
0271 template<
0272   typename Reducer,
0273   typename A
0274 > struct reduce<Reducer, A>
0275 {
0276   EIGEN_DEVICE_FUNC constexpr static EIGEN_STRONG_INLINE A run(A a) { return a; }
0277 };
0278 
0279 template<
0280   typename Reducer,
0281   typename A,
0282   typename... Ts
0283 > struct reduce<Reducer, A, Ts...>
0284 {
0285   EIGEN_DEVICE_FUNC constexpr static EIGEN_STRONG_INLINE auto run(A a, Ts... ts) -> decltype(Reducer::run(a, reduce<Reducer, Ts...>::run(ts...))) {
0286     return Reducer::run(a, reduce<Reducer, Ts...>::run(ts...));
0287   }
0288 };
0289 
0290 /* generic binary operations */
0291 
0292 struct sum_op           {
0293   template<typename A, typename B> EIGEN_DEVICE_FUNC constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a + b)   { return a + b;   }
0294   static constexpr int Identity = 0;
0295 };
0296 struct product_op       {
0297   template<typename A, typename B> EIGEN_DEVICE_FUNC constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a * b)   { return a * b;   }
0298   static constexpr int Identity = 1;
0299 };
0300 
0301 struct logical_and_op   { template<typename A, typename B> constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a && b)  { return a && b;  } };
0302 struct logical_or_op    { template<typename A, typename B> constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a || b)  { return a || b;  } };
0303 
0304 struct equal_op         { template<typename A, typename B> constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a == b)  { return a == b;  } };
0305 struct not_equal_op     { template<typename A, typename B> constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a != b)  { return a != b;  } };
0306 struct lesser_op        { template<typename A, typename B> constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a < b)   { return a < b;   } };
0307 struct lesser_equal_op  { template<typename A, typename B> constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a <= b)  { return a <= b;  } };
0308 struct greater_op       { template<typename A, typename B> constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a > b)   { return a > b;   } };
0309 struct greater_equal_op { template<typename A, typename B> constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a >= b)  { return a >= b;  } };
0310 
0311 /* generic unary operations */
0312 
0313 struct not_op                { template<typename A> constexpr static EIGEN_STRONG_INLINE auto run(A a) -> decltype(!a)      { return !a;      } };
0314 struct negation_op           { template<typename A> constexpr static EIGEN_STRONG_INLINE auto run(A a) -> decltype(-a)      { return -a;      } };
0315 struct greater_equal_zero_op { template<typename A> constexpr static EIGEN_STRONG_INLINE auto run(A a) -> decltype(a >= 0)  { return a >= 0;  } };
0316 
0317 
0318 /* reductions for lists */
0319 
0320 // using auto -> return value spec makes ICC 13.0 and 13.1 crash here, so we have to hack it
0321 // together in front... (13.0 doesn't work with array_prod/array_reduce/... anyway, but 13.1
0322 // does...
0323 template<typename... Ts>
0324 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE decltype(reduce<product_op, Ts...>::run((*((Ts*)0))...)) arg_prod(Ts... ts)
0325 {
0326   return reduce<product_op, Ts...>::run(ts...);
0327 }
0328 
0329 template<typename... Ts>
0330 constexpr EIGEN_STRONG_INLINE decltype(reduce<sum_op, Ts...>::run((*((Ts*)0))...)) arg_sum(Ts... ts)
0331 {
0332   return reduce<sum_op, Ts...>::run(ts...);
0333 }
0334 
0335 /* reverse arrays */
0336 
0337 template<typename Array, int... n>
0338 constexpr EIGEN_STRONG_INLINE Array h_array_reverse(Array arr, numeric_list<int, n...>)
0339 {
0340   return {{array_get<sizeof...(n) - n - 1>(arr)...}};
0341 }
0342 
0343 template<typename T, std::size_t N>
0344 constexpr EIGEN_STRONG_INLINE array<T, N> array_reverse(array<T, N> arr)
0345 {
0346   return h_array_reverse(arr, typename gen_numeric_list<int, N>::type());
0347 }
0348 
0349 
0350 /* generic array reductions */
0351 
0352 // can't reuse standard reduce() interface above because Intel's Compiler
0353 // *really* doesn't like it, so we just reimplement the stuff
0354 // (start from N - 1 and work down to 0 because specialization for
0355 // n == N - 1 also doesn't work in Intel's compiler, so it goes into
0356 // an infinite loop)
0357 template<typename Reducer, typename T, std::size_t N, std::size_t n = N - 1>
0358 struct h_array_reduce {
0359   EIGEN_DEVICE_FUNC constexpr static EIGEN_STRONG_INLINE auto run(array<T, N> arr, T identity) -> decltype(Reducer::run(h_array_reduce<Reducer, T, N, n - 1>::run(arr, identity), array_get<n>(arr)))
0360   {
0361     return Reducer::run(h_array_reduce<Reducer, T, N, n - 1>::run(arr, identity), array_get<n>(arr));
0362   }
0363 };
0364 
0365 template<typename Reducer, typename T, std::size_t N>
0366 struct h_array_reduce<Reducer, T, N, 0>
0367 {
0368   EIGEN_DEVICE_FUNC constexpr static EIGEN_STRONG_INLINE T run(const array<T, N>& arr, T)
0369   {
0370     return array_get<0>(arr);
0371   }
0372 };
0373 
0374 template<typename Reducer, typename T>
0375 struct h_array_reduce<Reducer, T, 0>
0376 {
0377   EIGEN_DEVICE_FUNC constexpr static EIGEN_STRONG_INLINE T run(const array<T, 0>&, T identity)
0378   {
0379     return identity;
0380   }
0381 };
0382 
0383 template<typename Reducer, typename T, std::size_t N>
0384 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE auto array_reduce(const array<T, N>& arr, T identity) -> decltype(h_array_reduce<Reducer, T, N>::run(arr, identity))
0385 {
0386   return h_array_reduce<Reducer, T, N>::run(arr, identity);
0387 }
0388 
0389 /* standard array reductions */
0390 
0391 template<typename T, std::size_t N>
0392 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE auto array_sum(const array<T, N>& arr) -> decltype(array_reduce<sum_op, T, N>(arr, static_cast<T>(0)))
0393 {
0394   return array_reduce<sum_op, T, N>(arr, static_cast<T>(0));
0395 }
0396 
0397 template<typename T, std::size_t N>
0398 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE auto array_prod(const array<T, N>& arr) -> decltype(array_reduce<product_op, T, N>(arr, static_cast<T>(1)))
0399 {
0400   return array_reduce<product_op, T, N>(arr, static_cast<T>(1));
0401 }
0402 
0403 template<typename t>
0404 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE t array_prod(const std::vector<t>& a) {
0405   eigen_assert(a.size() > 0);
0406   t prod = 1;
0407   for (size_t i = 0; i < a.size(); ++i) { prod *= a[i]; }
0408   return prod;
0409 }
0410 
0411 /* zip an array */
0412 
0413 template<typename Op, typename A, typename B, std::size_t N, int... n>
0414 constexpr EIGEN_STRONG_INLINE array<decltype(Op::run(A(), B())),N> h_array_zip(array<A, N> a, array<B, N> b, numeric_list<int, n...>)
0415 {
0416   return array<decltype(Op::run(A(), B())),N>{{ Op::run(array_get<n>(a), array_get<n>(b))... }};
0417 }
0418 
0419 template<typename Op, typename A, typename B, std::size_t N>
0420 constexpr EIGEN_STRONG_INLINE array<decltype(Op::run(A(), B())),N> array_zip(array<A, N> a, array<B, N> b)
0421 {
0422   return h_array_zip<Op>(a, b, typename gen_numeric_list<int, N>::type());
0423 }
0424 
0425 /* zip an array and reduce the result */
0426 
0427 template<typename Reducer, typename Op, typename A, typename B, std::size_t N, int... n>
0428 constexpr EIGEN_STRONG_INLINE auto h_array_zip_and_reduce(array<A, N> a, array<B, N> b, numeric_list<int, n...>) -> decltype(reduce<Reducer, typename id_numeric<int,n,decltype(Op::run(A(), B()))>::type...>::run(Op::run(array_get<n>(a), array_get<n>(b))...))
0429 {
0430   return reduce<Reducer, typename id_numeric<int,n,decltype(Op::run(A(), B()))>::type...>::run(Op::run(array_get<n>(a), array_get<n>(b))...);
0431 }
0432 
0433 template<typename Reducer, typename Op, typename A, typename B, std::size_t N>
0434 constexpr EIGEN_STRONG_INLINE auto array_zip_and_reduce(array<A, N> a, array<B, N> b) -> decltype(h_array_zip_and_reduce<Reducer, Op, A, B, N>(a, b, typename gen_numeric_list<int, N>::type()))
0435 {
0436   return h_array_zip_and_reduce<Reducer, Op, A, B, N>(a, b, typename gen_numeric_list<int, N>::type());
0437 }
0438 
0439 /* apply stuff to an array */
0440 
0441 template<typename Op, typename A, std::size_t N, int... n>
0442 constexpr EIGEN_STRONG_INLINE array<decltype(Op::run(A())),N> h_array_apply(array<A, N> a, numeric_list<int, n...>)
0443 {
0444   return array<decltype(Op::run(A())),N>{{ Op::run(array_get<n>(a))... }};
0445 }
0446 
0447 template<typename Op, typename A, std::size_t N>
0448 constexpr EIGEN_STRONG_INLINE array<decltype(Op::run(A())),N> array_apply(array<A, N> a)
0449 {
0450   return h_array_apply<Op>(a, typename gen_numeric_list<int, N>::type());
0451 }
0452 
0453 /* apply stuff to an array and reduce */
0454 
0455 template<typename Reducer, typename Op, typename A, std::size_t N, int... n>
0456 constexpr EIGEN_STRONG_INLINE auto h_array_apply_and_reduce(array<A, N> arr, numeric_list<int, n...>) -> decltype(reduce<Reducer, typename id_numeric<int,n,decltype(Op::run(A()))>::type...>::run(Op::run(array_get<n>(arr))...))
0457 {
0458   return reduce<Reducer, typename id_numeric<int,n,decltype(Op::run(A()))>::type...>::run(Op::run(array_get<n>(arr))...);
0459 }
0460 
0461 template<typename Reducer, typename Op, typename A, std::size_t N>
0462 constexpr EIGEN_STRONG_INLINE auto array_apply_and_reduce(array<A, N> a) -> decltype(h_array_apply_and_reduce<Reducer, Op, A, N>(a, typename gen_numeric_list<int, N>::type()))
0463 {
0464   return h_array_apply_and_reduce<Reducer, Op, A, N>(a, typename gen_numeric_list<int, N>::type());
0465 }
0466 
0467 /* repeat a value n times (and make an array out of it
0468  * usage:
0469  *   array<int, 16> = repeat<16>(42);
0470  */
0471 
0472 template<int n>
0473 struct h_repeat
0474 {
0475   template<typename t, int... ii>
0476   constexpr static EIGEN_STRONG_INLINE array<t, n> run(t v, numeric_list<int, ii...>)
0477   {
0478     return {{ typename id_numeric<int, ii, t>::type(v)... }};
0479   }
0480 };
0481 
0482 template<int n, typename t>
0483 constexpr array<t, n> repeat(t v) { return h_repeat<n>::run(v, typename gen_numeric_list<int, n>::type()); }
0484 
0485 /* instantiate a class by a C-style array */
0486 template<class InstType, typename ArrType, std::size_t N, bool Reverse, typename... Ps>
0487 struct h_instantiate_by_c_array;
0488 
0489 template<class InstType, typename ArrType, std::size_t N, typename... Ps>
0490 struct h_instantiate_by_c_array<InstType, ArrType, N, false, Ps...>
0491 {
0492   static InstType run(ArrType* arr, Ps... args)
0493   {
0494     return h_instantiate_by_c_array<InstType, ArrType, N - 1, false, Ps..., ArrType>::run(arr + 1, args..., arr[0]);
0495   }
0496 };
0497 
0498 template<class InstType, typename ArrType, std::size_t N, typename... Ps>
0499 struct h_instantiate_by_c_array<InstType, ArrType, N, true, Ps...>
0500 {
0501   static InstType run(ArrType* arr, Ps... args)
0502   {
0503     return h_instantiate_by_c_array<InstType, ArrType, N - 1, false, ArrType, Ps...>::run(arr + 1, arr[0], args...);
0504   }
0505 };
0506 
0507 template<class InstType, typename ArrType, typename... Ps>
0508 struct h_instantiate_by_c_array<InstType, ArrType, 0, false, Ps...>
0509 {
0510   static InstType run(ArrType* arr, Ps... args)
0511   {
0512     (void)arr;
0513     return InstType(args...);
0514   }
0515 };
0516 
0517 template<class InstType, typename ArrType, typename... Ps>
0518 struct h_instantiate_by_c_array<InstType, ArrType, 0, true, Ps...>
0519 {
0520   static InstType run(ArrType* arr, Ps... args)
0521   {
0522     (void)arr;
0523     return InstType(args...);
0524   }
0525 };
0526 
0527 template<class InstType, typename ArrType, std::size_t N, bool Reverse = false>
0528 InstType instantiate_by_c_array(ArrType* arr)
0529 {
0530   return h_instantiate_by_c_array<InstType, ArrType, N, Reverse>::run(arr);
0531 }
0532 
0533 } // end namespace internal
0534 
0535 } // end namespace Eigen
0536 
0537 #endif // EIGEN_CXX11META_H