stator
A math, geometry, and utility library
config.hpp
Go to the documentation of this file.
1 
4 /*
5  Copyright (C) 2017 Marcus N Campbell Bannerman <[email protected]>
6 
7  This file is part of stator.
8 
9  stator is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  stator is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with stator. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #pragma once
24 #include <Eigen/Dense>
25 
26 
51 #define STATOR_AUTORETURN(EXPR) decltype(EXPR) { return EXPR; }
52 
53 namespace stator {
55  template<typename Scalar, size_t D1, size_t D2> using Matrix = Eigen::Matrix<Scalar, D1, D2, Eigen::DontAlign>;
56 
58  template<typename Scalar, size_t D> using Vector = Matrix<Scalar, D, 1>;
59 
60  namespace detail {
61 
65  template<unsigned I> struct choice : choice<I+1> {};
66 
68  static const int LAST_OVERLOAD_LVL = 10;
69 
71  template<> struct choice<LAST_OVERLOAD_LVL> {};
72 
74 
76  struct select_overload : choice<0>{};
77 
78  template<class T> auto store_impl(T val, choice<0>) -> STATOR_AUTORETURN(typename std::decay<decltype(std::declval<T>().eval())>::type(val));
79  template<class T> auto store_impl(T val, choice<1>) -> STATOR_AUTORETURN(typename std::decay<T>::type(val));
80 
94  template<class T> auto store(const T& val) -> STATOR_AUTORETURN(store_impl(val, select_overload{}));
95 
96  template<class T> struct dependent_false: std::false_type {};
97  template<class T> struct dependent_true: std::true_type {};
98  } // namespace detail
99 } // namespace stator
100 
107 #define STATOR_AUTORETURN_BYVALUE(EXPR) STATOR_AUTORETURN(store(EXPR))
108 
A class which recursively inherits from itself to allow ambiguous function definition ordering...
Definition: config.hpp:65
The lowest-priority overload level (closing the recursion)
Definition: config.hpp:71
choice< LAST_OVERLOAD_LVL > last_choice
Definition: config.hpp:73
#define STATOR_AUTORETURN(EXPR)
A convenience Macro for defining auto return type functions.
Definition: config.hpp:51
auto store_impl(T val, choice< 0 >) -> decltype(typename std::decay< decltype(std::declval< T >().eval())>::type(val))
Definition: config.hpp:78
The stator library namespace.
Definition: frontpage.dox:243
A class used to start the ambiguous function definition ordering calculation.
Definition: config.hpp:76
Eigen::Matrix< Scalar, D1, D2, Eigen::DontAlign > Matrix
A convenience typedef for a non-aligned Eigen Matrix.
Definition: config.hpp:55
Matrix< Scalar, D, 1 > Vector
A convenience typedef for a non-aligned Eigen Vector.
Definition: config.hpp:58
auto store(const T &val) -> decltype(store_impl(val, select_overload
Definition: config.hpp:94