Skip to content

Instantly share code, notes, and snippets.

@picanumber
Last active November 28, 2016 00:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save picanumber/bba2339c5648b53355487cd97d2b70f7 to your computer and use it in GitHub Desktop.
Save picanumber/bba2339c5648b53355487cd97d2b70f7 to your computer and use it in GitHub Desktop.
int main()
{
int i1(1), i2(1);
char c1('o'), c2('k');
auto tp{ std::make_tuple(2., 4., 23, 7, 'x', 'l') };
std::array<char, 4> ar{ { 'a', 'b', 'c', 'd' } };
// 1. read from a slice -----------------------------------
std::tie(i1, i2) = tuple_slice<2, 4>(tp);
// 2. assign to a slice -----------------------------------
tuple_slice<0, 2>(ar) = std::tie(c1, c2);
// 3. apply a slice on a lambda ---------------------------
std::apply([](auto&& arg1, auto&& arg2) {
std::cout << "(" << arg1 << ", " << arg2 << ")\n";
}, tuple_slice<1, 3>(ar));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment