Skip to content

Instantly share code, notes, and snippets.

@nekko1119
Last active December 23, 2015 08:29
Show Gist options
  • Save nekko1119/6608479 to your computer and use it in GitHub Desktop.
Save nekko1119/6608479 to your computer and use it in GitHub Desktop.
引数群を受け取る練習。index tuple idiomを使う練習。VC++12.0で書きました。gccで動かすには`_Make_arg_idx`を`_Build_index_tuple`に、`_Arg_idx`を`_Index_tuple`に置き換えば動くと思います多分(確認していない)
#include <tuple>
#include <list>
#include <iostream>
using namespace std;
class hoge
{
public:
template <class... T1, class... T2>
hoge(tuple<T1...> t1, tuple<T2...> t2)
: hoge(move(t1), move(t2), typename _Make_arg_idx<T1...>::type(), typename _Make_arg_idx<T2...>::type())
{
}
private:
template <class... T1, class... T2, unsigned... I1, unsigned... I2>
hoge(tuple<T1...> t1, tuple<T2...> t2, _Arg_idx<I1...>, _Arg_idx<I2...>)
: int_list_(forward<T1>(get<I1>(t1))...),
double_list_(forward<T2>(get<I2>(t2))...)
{
}
//アクセサー書くの面倒臭かったので
public:
list<int> int_list_;
list<double> double_list_;
};
int main()
{
hoge h(forward_as_tuple(5, 10), forward_as_tuple(4, 3.14));
for (const auto& i : h.int_list_)
{
cout << i << endl;
}
cout << "----------------------\n";
for (const auto& i : h.double_list_)
{
cout << i << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment