CXX11Workarounds.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2013 Christian Seiler <christian@iwakd.de>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef EIGEN_CXX11WORKAROUNDS_H
11 #define EIGEN_CXX11WORKAROUNDS_H
12 
13 /* COMPATIBILITY CHECKS
14  * (so users of compilers that are too old get some realistic error messages)
15  */
16 #if defined(__INTEL_COMPILER) && (__INTEL_COMPILER < 1310)
17 #error Intel Compiler only supports required C++ features since version 13.1.
18 // note that most stuff in principle works with 13.0 but when combining
19 // some features, at some point 13.0 will just fail with an internal assertion
20 #elif defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 6))
21 // G++ < 4.6 by default will continue processing the source files - even if we use #error to make
22 // it error out. For this reason, we use the pragma to make sure G++ aborts at the first error
23 // it sees. Unfortunately, that is still not our #error directive, but at least the output is
24 // short enough the user has a chance to see that the compiler version is not sufficient for
25 // the funky template mojo we use.
26 #pragma GCC diagnostic error "-Wfatal-errors"
27 #error GNU C++ Compiler (g++) only supports required C++ features since version 4.6.
28 #endif
29 
30 namespace Eigen {
31 
32 namespace internal {
33 
34 /* std::get is only constexpr in C++14, not yet in C++11
35  */
36 
37 
38 template<std::size_t I_, class T> constexpr inline T& array_get(std::vector<T>& a) { return a[I_]; }
39 template<std::size_t I_, class T> constexpr inline T&& array_get(std::vector<T>&& a) { return a[I_]; }
40 template<std::size_t I_, class T> constexpr inline T const& array_get(std::vector<T> const& a) { return a[I_]; }
41 
42 /* Suppose you have a template of the form
43  * template<typename T> struct X;
44  * And you want to specialize it in such a way:
45  * template<typename S1, typename... SN> struct X<Foo<S1, SN...>> { ::: };
46  * template<> struct X<Foo<>> { ::: };
47  * This will work in Intel's compiler 13.0, but only to some extent in g++ 4.6, since
48  * g++ can only match templates called with parameter packs if the number of template
49  * arguments is not a fixed size (so inside the first specialization, referencing
50  * X<Foo<Sn...>> will fail in g++). On the other hand, g++ will accept the following:
51  * template<typename S...> struct X<Foo<S...>> { ::: }:
52  * as an additional (!) specialization, which will then only match the empty case.
53  * But Intel's compiler 13.0 won't accept that, it will only accept the empty syntax,
54  * so we have to create a workaround for this.
55  */
56 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
57 #define EIGEN_TPL_PP_SPEC_HACK_DEF(mt, n) mt... n
58 #define EIGEN_TPL_PP_SPEC_HACK_DEFC(mt, n) , EIGEN_TPL_PP_SPEC_HACK_DEF(mt, n)
59 #define EIGEN_TPL_PP_SPEC_HACK_USE(n) n...
60 #define EIGEN_TPL_PP_SPEC_HACK_USEC(n) , n...
61 #else
62 #define EIGEN_TPL_PP_SPEC_HACK_DEF(mt, n)
63 #define EIGEN_TPL_PP_SPEC_HACK_DEFC(mt, n)
64 #define EIGEN_TPL_PP_SPEC_HACK_USE(n)
65 #define EIGEN_TPL_PP_SPEC_HACK_USEC(n)
66 #endif
67 
68 } // end namespace internal
69 
70 } // end namespace Eigen
71 
72 #endif // EIGEN_CXX11WORKAROUNDS_H
73 
74 /*
75  * kate: space-indent on; indent-width 2; mixedindent off; indent-mode cstyle;
76  */
ArrayXXi a
constexpr T array_get(const numeric_list< T, a, as... > &)
: TensorContractionSycl.h, provides various tensor contraction kernel for SYCL backend