access.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
  2. // Copyright 2008-2016 National ICT Australia (NICTA)
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // ------------------------------------------------------------------------
  15. //! \addtogroup access
  16. //! @{
  17. class access
  18. {
  19. public:
  20. //! internal function to allow modification of data declared as read-only (use with caution)
  21. template<typename T1> arma_inline static T1& rw (const T1& x) { return const_cast<T1& >(x); }
  22. template<typename T1> arma_inline static T1*& rwp(const T1* const& x) { return const_cast<T1*&>(x); }
  23. //! internal function to obtain the real part of either a plain number or a complex number
  24. template<typename eT> arma_inline static const eT& tmp_real(const eT& X) { return X; }
  25. template<typename T> arma_inline static const T tmp_real(const std::complex<T>& X) { return X.real(); }
  26. //! internal function to obtain the imag part of either a plain number or a complex number
  27. template<typename eT> arma_inline static const eT tmp_imag(const eT ) { return eT(0); }
  28. template<typename T> arma_inline static const T tmp_imag(const std::complex<T>& X) { return X.imag(); }
  29. //! internal function to work around braindead compilers
  30. template<typename eT> arma_inline static const typename enable_if2<is_cx<eT>::no, const eT&>::result alt_conj(const eT& X) { return X; }
  31. template<typename eT> arma_inline static const typename enable_if2<is_cx<eT>::yes, const eT >::result alt_conj(const eT& X) { return std::conj(X); }
  32. };
  33. //! @}