diff options
author | Jim Guggemos <jimg@google.com> | 2012-12-04 16:46:41 -0700 |
---|---|---|
committer | Jim Guggemos <jimg@google.com> | 2012-12-04 17:08:38 -0700 |
commit | b015e75e8c7ba1ab4ddb91e9372a57e76f3fd159 (patch) | |
tree | 54d1c7d66098154c1d7c5bd414394ef4cf255810 /Eigen/src/Eigen2Support/Meta.h | |
parent | 63f67d748682b46d58be31235a0a2d64d81b998c (diff) | |
parent | c981c48f5bc9aefeffc0bcb0cc3934c2fae179dd (diff) | |
download | eigen-b015e75e8c7ba1ab4ddb91e9372a57e76f3fd159.tar.gz |
Merge 'goog/jb-mr1.1-dev' into platform/external/eigen.android-sdk-4.4.2_r1.0.1android-sdk-4.4.2_r1android-cts-4.4_r1android-4.4w_r1android-4.4_r0.7android-4.4.4_r2.0.1android-4.4.4_r2android-4.4.4_r1.0.1android-4.4.4_r1android-4.4.3_r1.1.0.1android-4.4.3_r1.1android-4.4.3_r1.0.1android-4.4.3_r1android-4.4.2_r2.0.1android-4.4.2_r2android-4.4.2_r1.0.1android-4.4.2_r1android-4.4.1_r1.0.1android-4.4.1_r1android-4.3_r3.1android-4.3_r3android-4.3.1_r1tools_r22.2tools_r22kitkat-wearkitkat-mr2.2-releasekitkat-mr2.1-releasekitkat-mr2-releasekitkat-mr1.1-releasekitkat-mr1-releasekitkat-devkitkat-cts-devjb-mr2.0.0-releasejb-mr2-devjb-mr1.1-dev-plus-aospjb-mr1-dev-plus-aospidea133-weekly-releaseidea133
Change-Id: Ic9004531328145ea36ba513bb96a23595427f6a4
Diffstat (limited to 'Eigen/src/Eigen2Support/Meta.h')
-rw-r--r-- | Eigen/src/Eigen2Support/Meta.h | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/Eigen/src/Eigen2Support/Meta.h b/Eigen/src/Eigen2Support/Meta.h new file mode 100644 index 000000000..fa37cfc96 --- /dev/null +++ b/Eigen/src/Eigen2Support/Meta.h @@ -0,0 +1,75 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2011 Benoit Jacob <jacob.benoit.1@gmail.com> +// +// This Source Code Form is subject to the terms of the Mozilla +// Public License v. 2.0. If a copy of the MPL was not distributed +// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN2_META_H +#define EIGEN2_META_H + +namespace Eigen { + +template<typename T> +struct ei_traits : internal::traits<T> +{}; + +struct ei_meta_true { enum { ret = 1 }; }; +struct ei_meta_false { enum { ret = 0 }; }; + +template<bool Condition, typename Then, typename Else> +struct ei_meta_if { typedef Then ret; }; + +template<typename Then, typename Else> +struct ei_meta_if <false, Then, Else> { typedef Else ret; }; + +template<typename T, typename U> struct ei_is_same_type { enum { ret = 0 }; }; +template<typename T> struct ei_is_same_type<T,T> { enum { ret = 1 }; }; + +template<typename T> struct ei_unref { typedef T type; }; +template<typename T> struct ei_unref<T&> { typedef T type; }; + +template<typename T> struct ei_unpointer { typedef T type; }; +template<typename T> struct ei_unpointer<T*> { typedef T type; }; +template<typename T> struct ei_unpointer<T*const> { typedef T type; }; + +template<typename T> struct ei_unconst { typedef T type; }; +template<typename T> struct ei_unconst<const T> { typedef T type; }; +template<typename T> struct ei_unconst<T const &> { typedef T & type; }; +template<typename T> struct ei_unconst<T const *> { typedef T * type; }; + +template<typename T> struct ei_cleantype { typedef T type; }; +template<typename T> struct ei_cleantype<const T> { typedef typename ei_cleantype<T>::type type; }; +template<typename T> struct ei_cleantype<const T&> { typedef typename ei_cleantype<T>::type type; }; +template<typename T> struct ei_cleantype<T&> { typedef typename ei_cleantype<T>::type type; }; +template<typename T> struct ei_cleantype<const T*> { typedef typename ei_cleantype<T>::type type; }; +template<typename T> struct ei_cleantype<T*> { typedef typename ei_cleantype<T>::type type; }; + +/** \internal In short, it computes int(sqrt(\a Y)) with \a Y an integer. + * Usage example: \code ei_meta_sqrt<1023>::ret \endcode + */ +template<int Y, + int InfX = 0, + int SupX = ((Y==1) ? 1 : Y/2), + bool Done = ((SupX-InfX)<=1 ? true : ((SupX*SupX <= Y) && ((SupX+1)*(SupX+1) > Y))) > + // use ?: instead of || just to shut up a stupid gcc 4.3 warning +class ei_meta_sqrt +{ + enum { + MidX = (InfX+SupX)/2, + TakeInf = MidX*MidX > Y ? 1 : 0, + NewInf = int(TakeInf) ? InfX : int(MidX), + NewSup = int(TakeInf) ? int(MidX) : SupX + }; + public: + enum { ret = ei_meta_sqrt<Y,NewInf,NewSup>::ret }; +}; + +template<int Y, int InfX, int SupX> +class ei_meta_sqrt<Y, InfX, SupX, true> { public: enum { ret = (SupX*SupX <= Y) ? SupX : InfX }; }; + +} // end namespace Eigen + +#endif // EIGEN2_META_H |