C++14 で名前付き引数
標準ライブラリでできる範囲で書いてみました。
[ソース]
#include <tuple> template<typename T, typename Uniq> struct holder{ T value; operator T(){ return value; } holder& operator =(T t){ value = t; return *this; } }; template<typename T, typename Uniq, typename ...Args> T get(holder<T, Uniq>, Args... args){ return std::get<holder<T, Uniq>>(std::make_tuple(args...)); } #include <iostream> #include <string> holder<int, struct age_> age; holder<int, struct index_> id; holder<std::string, struct name_> name; template<typename ...Args> void func(Args... args){ std::cout << "id = " << ::get(id, args...) << std::endl; std::cout << "age = " << ::get(age, args...) << std::endl; std::cout << "name = " << ::get(name, args...) << std::endl; } int main(){ func(age = 13, name = "homu", id = 0); func(id = 1, name = "mami", age = 14); return 0; }