arma_static_check.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 arma_static_check
  16. //! @{
  17. template<bool ERROR___TYPE_MISMATCH_OR_UNSUPPORTED_TYPE>
  18. struct arma_type_check_cxx1998
  19. {
  20. arma_inline
  21. static
  22. void
  23. apply()
  24. {
  25. static const char
  26. junk[ ERROR___TYPE_MISMATCH_OR_UNSUPPORTED_TYPE ? -1 : +1 ];
  27. }
  28. };
  29. template<>
  30. struct arma_type_check_cxx1998<false>
  31. {
  32. arma_inline
  33. static
  34. void
  35. apply()
  36. {
  37. }
  38. };
  39. #undef arma_static_check
  40. #undef arma_type_check
  41. #if defined(ARMA_USE_CXX11)
  42. #define arma_static_check(condition, message) static_assert( !(condition), #message )
  43. #define arma_type_check(condition) static_assert( !(condition), "error: type mismatch or unsupported type" )
  44. #else
  45. #define arma_static_check(condition, message) static const char message[ (condition) ? -1 : +1 ]
  46. #define arma_type_check(condition) arma_type_check_cxx1998<condition>::apply()
  47. #endif
  48. //! @}