Created
April 15, 2017 15:22
-
-
Save mtao/1b5f82377f109288d25901e8c8049e4f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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