Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Sep 15th, 2015 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <array>
  2. #include <string>
  3. #include <type_traits>
  4.  
  5. template < typename T, size_t ROWS, size_t COLS >
  6. class Matrix
  7. {
  8. private:
  9.     std::array< T, ROWS * COLS > m_cValues;
  10.  
  11. public:
  12.     Matrix( void )
  13.     {
  14.         m_cValues.fill( static_cast<T>( 0 ) );
  15.     }
  16.  
  17.     ~Matrix( )
  18.     {
  19.     }
  20.  
  21.     explicit Matrix( std::array< T, ROWS * COLS > cValues ) : m_cValues( cValues )
  22.     {
  23.     }
  24.  
  25.     template < typename... Args >
  26.     Matrix( Args ... args ) : m_cValues{ static_cast<T>( args )... }
  27.     {
  28.     }
  29.  
  30.     auto row( size_t iRow, Matrix< T, 1, COLS > mat ) -> void
  31.     {
  32.         for ( size_t i = 0; i < COLS; ++i )
  33.             at( iRow, i ) = mat( i );
  34.     }
  35.  
  36.     auto col( size_t iCol, Matrix< T, ROWS, 1 > mat ) -> void
  37.     {
  38.         for ( size_t i = 0; i < ROWS; ++i )
  39.             at( i, iCol ) = mat( i );
  40.     }
  41.  
  42.     auto at( size_t i ) -> T&
  43.     {
  44.         return m_cValues.at( i );
  45.     }
  46.  
  47.     auto at( size_t i ) const -> const T&
  48.     {
  49.         return m_cValues.at( i );
  50.     }
  51.  
  52.         auto at( size_t iRow, size_t iCol ) -> T&
  53.     {
  54.         return m_cValues.at( iRow * COLS + iCol );
  55.     }
  56.  
  57.     auto at( size_t iRow, size_t iCol ) const -> const T&
  58.     {
  59.         return m_cValues.at( iRow * COLS + iCol );
  60.     }
  61.  
  62.         auto operator()( size_t i ) -> T&
  63.     {
  64.         return at( i );
  65.     }
  66. };
  67.  
  68. auto main( ) -> int
  69. {
  70.     using Vector3 = Matrix< float, 3, 1 >;
  71.  
  72.     auto mat = Matrix< float, 3, 3 >{
  73.         3, 5.f, 7,
  74.         1, 0, -3,
  75.         5, 13.0, 21,
  76.     };
  77.  
  78.     auto v = Vector3{ 1,2,3.f };
  79.     mat.row( 1, { 9, 6.f, 3 } );
  80. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top