c++ - ::std::pair in a variadic function template -
It is possible to write a variadic function template, accept
:: std :: pair
Without making the couple manually: void print_pairs () {} template & lt; Typename ... B & gt; Zero print_pairs (:: std :: pair & lt; int, int & gt; const & a, b & ... b) {:: std :: cout & lt; & Lt; A.first & lt; & Lt; "" & Lt; & Lt; A.second & lt; & Lt; Std :: endl ::; Print_pairs (:: STD are ahead & lt ::; p & gt; (b) ...); }
but I want to be able to write print_pairs ({1, 1}, {2, 2});
, instead of using :: std :: make_pair
every time
Edit:
After thinking about something, the best solution can be old school:
print_pairs (:: std :: pair & Lt; int, int> const & amp;); Print_pairs (:: std :: pair and lt; int, int & gt; const & amp;; :: std :: pair & lt; int, int & gt; const & amp;;); Print_pairs (:: std :: pair & lt; int, int & gt; const & amp;; :: std :: pair & gt; int, int & gt; const & amp;; :: std :: pair & lt ; Int, int> const & amp ;;);
and so on ...
If you just want To print two numbers per line, why not std :: pair
s be prepared at all?
void print_pairs () {} template & lt; Typename t, typename u, type name ... Rest & gt; Zero Print_Pear (Constant and A, Constant and End, Constant Rest and the rest ...) {std :: cout & lt; & Lt; A & lt; & Lt; "" & Lt; & Lt; B & L; & Lt; '\ N'; Print_pairs (rest ...); } Int main () {print_pairs (1, 1, 2, 2); }
If you really need to add, then create them within the template of the template:
template & lt; Typename t, typename u, typename ... left & gt; Zero print_pairs (T & amp; A, U & amp; A, Relax & ... rest) {auto p = std :: make_pair (std :: forward & lt; T & gt; (A), std: : Forward & lt; U & gt; (b)); // ... print_payer (std :: forward & lt; rest & gt; (rest) ...); }
Comments
Post a Comment