Created
September 14, 2013 15:37
-
-
Save lichray/6562999 to your computer and use it in GitHub Desktop.
Simulate std::tie's functionality for the input iterators.
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 <tuple> | |
template <typename Iter, typename T1> | |
inline auto tie_from(Iter it, T1& t1) | |
-> std::tuple<T1&> | |
{ | |
t1 = *it; | |
return std::tuple<T1&>(t1); | |
} | |
template <typename Iter, typename T1, typename... T2> | |
inline auto tie_from(Iter it, T1& t1, T2&... t2) | |
-> std::tuple<T1&, T2&...> | |
{ | |
t1 = *it++; | |
return std::tuple_cat(std::tuple<T1&>(t1), tie_from(it, t2...)); | |
} | |
#include <iostream> | |
#include <list> | |
int main() | |
{ | |
std::list<int> ls = { 3, 4, 5 }; | |
int x, y; | |
auto t = tie_from(begin(ls), x, y); | |
std::cout << x << ' ' << y << std::endl; | |
std::get<0>(t) = 8; | |
std::cout << x << ' ' << y << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment