Skip to content

Instantly share code, notes, and snippets.

@bl4ckb0ne
Created October 26, 2016 14:15
Show Gist options
  • Save bl4ckb0ne/a9b7944330523a94521a329408bd5e4e to your computer and use it in GitHub Desktop.
Save bl4ckb0ne/a9b7944330523a94521a329408bd5e4e to your computer and use it in GitHub Desktop.
// Example program
#include <iostream>
#include <string>
#include <vector>
template<typename T>
void print(std::vector<T>& v)
{
for(auto it : v)
std::cout << it << " ";
std::cout << '\n';
}
template<typename T>
std::vector<T> matrix_extend(std::vector<T>& v1, std::vector<T>& v2)
{
std::cout << __PRETTY_FUNCTION__ << "\n";
std::vector<int> ret;
std::cout << "v1 " << v1.size() << '\n';
print(v1);
std::cout << "v2 " << v2.size() << '\n';
print(v2);
for(size_t i = 0; i < 3; i++)
{
for(size_t j = 0; j < (v1.size() / 3); j++)
{
ret.push_back(v1[i * (v1.size() / 3) + j]);
print(ret);
}
for(size_t k = 0; k < (v2.size() / 3); k++)
{
ret.push_back(v2[i * (v2.size() / 3) + k]);
print(ret);
}
}
return ret;
}
template<typename T, typename... Args>
std::vector<T> matrix_extend(std::vector<T>& v1, std::vector<T>& v2, Args... args)
{
std::cout << __PRETTY_FUNCTION__ << "\n";
std::vector<int> ret;
std::cout << "v1\n";
print(v1);
std::cout << "v2\n";
print(v2);
for(size_t i = 0; i < 3; i++)
{
for(size_t j = 0; j < (v1.size() / 3); j++)
{
ret.push_back(v1[i * (v1.size() / 3) + j]);
print(ret);
}
for(size_t k = 0; k < (v2.size() / 3); k++)
{
ret.push_back(v2[i * (v2.size() / 3) + k]);
print(ret);
}
}
return matrix_extend(ret, args...);
}
int main()
{
std::vector<int> v1 = {
1, 1, 1,
1, 1, 1,
1, 1, 1
};
std::vector<int> v2 = {
2, 2, 2,
2, 2, 2,
2, 2, 2
};
std::vector<int> v3 = {
3, 3, 3,
3, 3, 3,
3, 3, 3
};
std::vector<int> v4 = {
4, 4, 4,
4, 4, 4,
4, 4, 4
};
//std::vector<int> v = matrix_extend(v1, v2, v3);
std::vector<int> v = matrix_extend(v1, v2, v3, v4);
std::cout << __PRETTY_FUNCTION__ << "\n";
print(v);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment