Skip to content

Instantly share code, notes, and snippets.

@mtao
Created April 15, 2017 15:22
Show Gist options
  • Save mtao/1b5f82377f109288d25901e8c8049e4f to your computer and use it in GitHub Desktop.
Save mtao/1b5f82377f109288d25901e8c8049e4f to your computer and use it in GitHub Desktop.
#include <iostream>
#include <Eigen/Core>
//Mimics http://stackoverflow.com/a/40958644
template <typename Scalar, int D, int E, int... Is>
auto eigen_unpack_impl(const Eigen::Matrix<Scalar, D, E>& a, std::integer_sequence<int,Is...>) {
return std::tie( a(Is)... );
}
template <typename Scalar, int D, int E>
auto eigen_unpack(const Eigen::Matrix<Scalar, D, E>& a) {
static_assert(D == 1 || E == 1, "ONLY VECTORS");
return eigen_unpack_impl(a,std::make_integer_sequence<int,D*E>{});
}
int main(int argc, char * argv[]) {
int a,b,c;
std::tie(a,b,c) = eigen_unpack(Eigen::Vector3d(2.0,3.0,4.0));
std::cout << a << " " << b << " " << c << std::endl;
std::tie(a,b,c) = eigen_unpack(Eigen::RowVector3d(2.0,3.0,4.0));
std::cout << a << " " << b << " " << c << std::endl;
Eigen::Vector3d w(6,7,8);
//auto& [x,y,z] = eigen_unpack(w);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment