Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6904195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:01:25+00:00 2026-05-27T08:01:25+00:00

Given #include <utility> template <typename T1, typename T2, typename T3> void foo(std::initializer_list<std::pair<T1, T2>> _a,

  • 0

Given

#include <utility>
template <typename T1, typename T2, typename T3>
void foo(std::initializer_list<std::pair<T1, T2>> _a, std::initializer_list<T3> _b) {
    /* ... */
}

int main() {
        foo({{1,2},{3,4}},{1,2,3,4,5});
}

why does gcc 4.6 produce the error

error: no matching function for call to ‘foo(<brace-enclosed initializer list>, <brace-enclosed initializer list>)'

note: candidate is

note: template<class T1, class T2, class T3> void foo(std::initializer_list<std::pair<T1, T2> >, std::initializer_list<T3>)

Update
Now works when

template <typename T1, typename T2>
std::pair<T1, T2> p(const T1& _1, const T2& _2) {
    return std::make_pair(_1, _2);
}

is added and {{1,2},{3,4}} is replaced with {p(1,2), p(3,4)}.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:01:26+00:00Added an answer on May 27, 2026 at 8:01 am

    What you’re trying to do is basically chained conversion/invocation, which is not allowed in C++.

    First you want to convert this,

    {{1,2},{3,4}}
    

    into this (while deducing the type argument),

    {std::pair<int,int>{1,2},std::pair<int,int>{3,4}}
    

    which then into std::initializer_list. It is not allowed.

    You’ve to do one conversion yourself:

    foo( {std::pair<int,int>{1,2},std::pair<int,int>{3,4}}, {1,2,3,4,5});
    

    then it will compile : http://ideone.com/bRJqV

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include <initializer_list> #include <utility> void foo(std::initializer_list<std::pair<int,int>>) {} template <class T> void bar(T) {} int
Given the code: #include <iostream> using namespace std; template <typename T> T my_max (const
consider the code #include<stdio.h> int main(void) { char* a; scanf(%s,a);//&a and &a[0] give same
Given this code: #include <iostream> using namespace std; class Foo { public: Foo ()
So, given the following: #include <stdio.h> int * getarr(); int main(int argc, char* argv)
Given this sample code: #include <iostream> #include <stdexcept> class my_exception_t : std::exception { public:
Given the following function templates: #include <vector> #include <utility> struct Base { }; struct
Given the code: #include <iostream> #include <cctype> #include <string> #include <algorithm> using namespace std;
Given #include <locale> struct Q; struct R{ void operator()(Q*) { } }; class S
Given the files: // file: q7a.h static int err_code = 3; void printErrCode ();

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.