Base.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2009 NICTA
00002 // 
00003 // Authors:
00004 // - Conrad Sanderson (conradsand at ieee dot org)
00005 // 
00006 // This file is part of the Armadillo C++ library.
00007 // It is provided without any warranty of fitness
00008 // for any purpose. You can redistribute this file
00009 // and/or modify it under the terms of the GNU
00010 // Lesser General Public License (LGPL) as published
00011 // by the Free Software Foundation, either version 3
00012 // of the License or (at your option) any later version.
00013 // (see http://www.opensource.org/licenses for more info)
00014 
00015 
00016 //! \addtogroup Base
00017 //! @{
00018 
00019 
00020 
00021 //! Class for static polymorphism, modelled after the "Curiously Recurring Template Pattern" (CRTP).
00022 //! Used for type-safe downcasting in functions that restrict their input(s) to be classes that are
00023 //! derived from Base (e.g. Mat, Op, Glue, diagview, subview).
00024 //! A Base object can be converted to a Mat object by the unwrap class.
00025 
00026 template<typename elem_type, typename derived>
00027 struct Base
00028   {
00029   
00030   arma_inline
00031   const derived&
00032   get_ref() const
00033     {
00034     return static_cast<const derived&>(*this);
00035     }
00036 
00037   };
00038 
00039 
00040 
00041 template<typename elem_type, typename derived>
00042 struct BaseVec
00043   {
00044   
00045   arma_inline
00046   const derived&
00047   get_ref() const
00048     {
00049     return static_cast<const derived&>(*this);
00050     }
00051 
00052   };
00053 
00054 
00055 
00056 //! @}