Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GaussianProcessTuning/HeuristicLab.Eigen/Eigen/src/Eigen2Support/Meta.h @ 9562

Last change on this file since 9562 was 9562, checked in by gkronber, 11 years ago

#1967 worked on Gaussian process evolution.

File size: 2.9 KB
Line 
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2011 Benoit Jacob <jacob.benoit.1@gmail.com>
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 EIGEN2_META_H
11#define EIGEN2_META_H
12
13namespace Eigen {
14
15template<typename T>
16struct ei_traits : internal::traits<T>
17{};
18
19struct ei_meta_true {  enum { ret = 1 }; };
20struct ei_meta_false { enum { ret = 0 }; };
21
22template<bool Condition, typename Then, typename Else>
23struct ei_meta_if { typedef Then ret; };
24
25template<typename Then, typename Else>
26struct ei_meta_if <false, Then, Else> { typedef Else ret; };
27
28template<typename T, typename U> struct ei_is_same_type { enum { ret = 0 }; };
29template<typename T> struct ei_is_same_type<T,T> { enum { ret = 1 }; };
30
31template<typename T> struct ei_unref { typedef T type; };
32template<typename T> struct ei_unref<T&> { typedef T type; };
33
34template<typename T> struct ei_unpointer { typedef T type; };
35template<typename T> struct ei_unpointer<T*> { typedef T type; };
36template<typename T> struct ei_unpointer<T*const> { typedef T type; };
37
38template<typename T> struct ei_unconst { typedef T type; };
39template<typename T> struct ei_unconst<const T> { typedef T type; };
40template<typename T> struct ei_unconst<T const &> { typedef T & type; };
41template<typename T> struct ei_unconst<T const *> { typedef T * type; };
42
43template<typename T> struct ei_cleantype { typedef T type; };
44template<typename T> struct ei_cleantype<const T>   { typedef typename ei_cleantype<T>::type type; };
45template<typename T> struct ei_cleantype<const T&>  { typedef typename ei_cleantype<T>::type type; };
46template<typename T> struct ei_cleantype<T&>        { typedef typename ei_cleantype<T>::type type; };
47template<typename T> struct ei_cleantype<const T*>  { typedef typename ei_cleantype<T>::type type; };
48template<typename T> struct ei_cleantype<T*>        { typedef typename ei_cleantype<T>::type type; };
49
50/** \internal In short, it computes int(sqrt(\a Y)) with \a Y an integer.
51  * Usage example: \code ei_meta_sqrt<1023>::ret \endcode
52  */
53template<int Y,
54         int InfX = 0,
55         int SupX = ((Y==1) ? 1 : Y/2),
56         bool Done = ((SupX-InfX)<=1 ? true : ((SupX*SupX <= Y) && ((SupX+1)*(SupX+1) > Y))) >
57                                // use ?: instead of || just to shut up a stupid gcc 4.3 warning
58class ei_meta_sqrt
59{
60    enum {
61      MidX = (InfX+SupX)/2,
62      TakeInf = MidX*MidX > Y ? 1 : 0,
63      NewInf = int(TakeInf) ? InfX : int(MidX),
64      NewSup = int(TakeInf) ? int(MidX) : SupX
65    };
66  public:
67    enum { ret = ei_meta_sqrt<Y,NewInf,NewSup>::ret };
68};
69
70template<int Y, int InfX, int SupX>
71class ei_meta_sqrt<Y, InfX, SupX, true> { public:  enum { ret = (SupX*SupX <= Y) ? SupX : InfX }; };
72
73} // end namespace Eigen
74
75#endif // EIGEN2_META_H
Note: See TracBrowser for help on using the repository browser.