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) && \
21  (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 6))
22 // G++ < 4.6 by default will continue processing the source files - even if we use #error to make
23 // it error out. For this reason, we use the pragma to make sure G++ aborts at the first error
24 // it sees. Unfortunately, that is still not our #error directive, but at least the output is
25 // short enough the user has a chance to see that the compiler version is not sufficient for
26 // the funky template mojo we use.
27 #pragma GCC diagnostic error "-Wfatal-errors"
28 #error GNU C++ Compiler (g++) only supports required C++ features since version 4.6.
29 #endif
30 
31 namespace Eigen {
32 
33 namespace internal {
34 
35 /* std::get is only constexpr in C++14, not yet in C++11
36  */
37 
38 template <std::size_t I_, class T>
39 constexpr inline T& array_get(std::vector<T>& a) {
40  return a[I_];
41 }
42 template <std::size_t I_, class T>
43 constexpr inline T&& array_get(std::vector<T>&& a) {
44  return a[I_];
45 }
46 template <std::size_t I_, class T>
47 constexpr inline T const& array_get(std::vector<T> const& a) {
48  return a[I_];
49 }
50 
51 /* Suppose you have a template of the form
52  * template<typename T> struct X;
53  * And you want to specialize it in such a way:
54  * template<typename S1, typename... SN> struct X<Foo<S1, SN...>> { ::: };
55  * template<> struct X<Foo<>> { ::: };
56  * This will work in Intel's compiler 13.0, but only to some extent in g++ 4.6, since
57  * g++ can only match templates called with parameter packs if the number of template
58  * arguments is not a fixed size (so inside the first specialization, referencing
59  * X<Foo<Sn...>> will fail in g++). On the other hand, g++ will accept the following:
60  * template<typename S...> struct X<Foo<S...>> { ::: }:
61  * as an additional (!) specialization, which will then only match the empty case.
62  * But Intel's compiler 13.0 won't accept that, it will only accept the empty syntax,
63  * so we have to create a workaround for this.
64  */
65 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
66 #define EIGEN_TPL_PP_SPEC_HACK_DEF(mt, n) mt... n
67 #define EIGEN_TPL_PP_SPEC_HACK_DEFC(mt, n) , EIGEN_TPL_PP_SPEC_HACK_DEF(mt, n)
68 #define EIGEN_TPL_PP_SPEC_HACK_USE(n) n...
69 #define EIGEN_TPL_PP_SPEC_HACK_USEC(n) , n...
70 #else
71 #define EIGEN_TPL_PP_SPEC_HACK_DEF(mt, n)
72 #define EIGEN_TPL_PP_SPEC_HACK_DEFC(mt, n)
73 #define EIGEN_TPL_PP_SPEC_HACK_USE(n)
74 #define EIGEN_TPL_PP_SPEC_HACK_USEC(n)
75 #endif
76 
77 } // end namespace internal
78 
79 } // end namespace Eigen
80 
81 #endif // EIGEN_CXX11WORKAROUNDS_H
82 
83 /*
84  * kate: space-indent on; indent-width 2; mixedindent off; indent-mode cstyle;
85  */
const Scalar * a
Definition: level2_cplx_impl.h:32
constexpr T & array_get(std::array< T, N > &a)
Definition: EmulateArray.h:251
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
Definition: Eigen_Colamd.h:49