Tr (Transpose)
Abstract
Tr()
are the transpose functions for std::vector<std::vector<T>>
.
Tr()
は std::vector<std::vector<T>>
を転置するための関数です.
Header file
namespace sstd{
template <typename T> std::vector<std::vector<T>> Tr(const std::vector<std::vector<T>>& rhs);
template <typename T> std::vector<std::vector<T>> Tr( std::vector<std::vector<T>>&& rhs);
}
Usage
Transpose. Ex: 1
- main.cpp
#include <sstd/sstd.hpp> int main(){ std::vector<std::vector<int>> vvec = { { 1, 2, 3 } }; sstd::printn(vvec); std::vector<std::vector<int>> vvecTr = sstd::Tr(vvec); sstd::printn(vvecTr); }
- Execution result
vvec = [[1 2 3]] vvecTr = [[1] [2] [3]]
Transpose. Ex: 2
- main.cpp
#include <sstd/sstd.hpp> int main(){ std::vector<std::vector<int>> vvec = { { 1, 2, 3}, { 4, 5, 6}, { 7, 8, 9} }; sstd::printn(vvec); std::vector<std::vector<int>> vvecTr = sstd::Tr(vvec); sstd::printn(vvecTr); }
- Execution result
vvec = [[1 2 3] [4 5 6] [7 8 9]] vvecTr = [[1 4 7] [2 5 8] [3 6 9]]
Transpose. Ex: 3
- main.cpp
#include <sstd/sstd.hpp> int main(){ std::vector<std::vector<int>> vvec = { { 1}, { 2, 3}, { 4, 5, 6} }; sstd::printn(vvec); std::vector<std::vector<int>> vvecTr = sstd::Tr(vvec); sstd::printn(vvecTr); }
- Execution result
vvec = [[1] [2 3] [4 5 6]] vvecTr = [[1 2 4] [0 3 5] [0 0 6]]
Implementation
- Header: sstd/src/vector/vvec.hpp
- Test: test/vector_vvec.hpp