c_array.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /**
  2. * -*- c++ -*-
  3. *
  4. * \file c_array.hpp
  5. *
  6. * \brief provides specializations of matrix and vector traits for c arrays and c matrices.
  7. *
  8. * Copyright (c) 2009, Gunter Winkler
  9. *
  10. * Distributed under the Boost Software License, Version 1.0. (See
  11. * accompanying file LICENSE_1_0.txt or copy at
  12. * http://www.boost.org/LICENSE_1_0.txt)
  13. *
  14. * \author Gunter Winkler (guwi17 at gmx dot de)
  15. */
  16. #ifndef BOOST_NUMERIC_UBLAS_TRAITS_C_ARRAY_HPP
  17. #define BOOST_NUMERIC_UBLAS_TRAITS_C_ARRAY_HPP
  18. #include <boost/numeric/ublas/traits.hpp>
  19. #include <boost/numeric/ublas/traits/const_iterator_type.hpp>
  20. #include <boost/numeric/ublas/traits/iterator_type.hpp>
  21. namespace boost { namespace numeric { namespace ublas {
  22. namespace detail {
  23. }
  24. template < class T, int M, int N >
  25. struct matrix_view_traits < T[M][N] > {
  26. typedef T matrix_type[M][N];
  27. typedef std::size_t size_type;
  28. typedef std::ptrdiff_t difference_type;
  29. typedef row_major_tag orientation_category;
  30. typedef dense_tag storage_category;
  31. typedef T value_type;
  32. typedef const T &const_reference;
  33. typedef const T *const_pointer;
  34. typedef const matrix_reference<const matrix_type> const_closure_type;
  35. typedef T row_type[N];
  36. typedef const row_type *const_iterator1;
  37. typedef const_pointer const_iterator2;
  38. };
  39. template < class T, int M, int N >
  40. struct mutable_matrix_traits < T[M][N] > {
  41. typedef T matrix_type[M][N];
  42. typedef T *reference;
  43. typedef matrix_reference<matrix_type> closure_type;
  44. };
  45. template < class T, int N >
  46. struct vector_view_traits < T[N] > {
  47. typedef T vector_type[N];
  48. typedef std::size_t size_type;
  49. typedef std::ptrdiff_t difference_type;
  50. typedef dense_tag storage_category;
  51. typedef T value_type;
  52. typedef const T &const_reference;
  53. typedef const T *const_pointer;
  54. typedef const vector_reference<const vector_type> const_closure_type;
  55. typedef const_pointer const_iterator;
  56. /// iterator pointing to the first element
  57. static
  58. const_iterator begin(const vector_type & v) {
  59. return & (v[0]);
  60. }
  61. /// iterator pointing behind the last element
  62. static
  63. const_iterator end(const vector_type & v) {
  64. return & (v[N]);
  65. }
  66. };
  67. template < class T, int N >
  68. struct mutable_vector_traits < T[N] > {
  69. typedef T &reference;
  70. typedef T *pointer;
  71. typedef vector_reference< T[N] > closure_type;
  72. };
  73. }}} // Namespace boost::numeric::ublas
  74. #endif