Logo Search packages:      
Sourcecode: eigen3 version File versions  Download package

Meta.h
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2011 Benoit Jacob <jacob.benoit.1@gmail.com>
//
// Eigen is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// Alternatively, you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of
// the License, or (at your option) any later version.
//
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License and a copy of the GNU General Public License along with
// Eigen. If not, see <http://www.gnu.org/licenses/>.

#ifndef EIGEN2_META_H
#define EIGEN2_META_H

template<typename T>
00029 struct ei_traits : internal::traits<T>
{};

00032 struct ei_meta_true {  enum { ret = 1 }; };
00033 struct ei_meta_false { enum { ret = 0 }; };

template<bool Condition, typename Then, typename Else>
00036 struct ei_meta_if { typedef Then ret; };

template<typename Then, typename Else>
00039 struct ei_meta_if <false, Then, Else> { typedef Else ret; };

00041 template<typename T, typename U> struct ei_is_same_type { enum { ret = 0 }; };
00042 template<typename T> struct ei_is_same_type<T,T> { enum { ret = 1 }; };

00044 template<typename T> struct ei_unref { typedef T type; };
00045 template<typename T> struct ei_unref<T&> { typedef T type; };

00047 template<typename T> struct ei_unpointer { typedef T type; };
00048 template<typename T> struct ei_unpointer<T*> { typedef T type; };
00049 template<typename T> struct ei_unpointer<T*const> { typedef T type; };

00051 template<typename T> struct ei_unconst { typedef T type; };
00052 template<typename T> struct ei_unconst<const T> { typedef T type; };
00053 template<typename T> struct ei_unconst<T const &> { typedef T & type; };
00054 template<typename T> struct ei_unconst<T const *> { typedef T * type; };

00056 template<typename T> struct ei_cleantype { typedef T type; };
00057 template<typename T> struct ei_cleantype<const T>   { typedef typename ei_cleantype<T>::type type; };
00058 template<typename T> struct ei_cleantype<const T&>  { typedef typename ei_cleantype<T>::type type; };
00059 template<typename T> struct ei_cleantype<T&>        { typedef typename ei_cleantype<T>::type type; };
00060 template<typename T> struct ei_cleantype<const T*>  { typedef typename ei_cleantype<T>::type type; };
00061 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
00071 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>
00084 class ei_meta_sqrt<Y, InfX, SupX, true> { public:  enum { ret = (SupX*SupX <= Y) ? SupX : InfX }; };

#endif // EIGEN2_META_H

Generated by  Doxygen 1.6.0   Back to index