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

  • SEARCH
  • Home
  • 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 7495465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:09:10+00:00 2026-05-29T18:09:10+00:00

What is the purpose of std::make_pair ? Why not just do std::pair<int, char>(0, ‘a’)

  • 0

What is the purpose of std::make_pair?

Why not just do std::pair<int, char>(0, 'a')?

Is there any difference between the two methods?

  • 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-29T18:09:15+00:00Added an answer on May 29, 2026 at 6:09 pm

    (This answer is only correct for C++14 and earlier standards, due to CTAD)

    The difference is that with std::pair you need to specify the types of both elements, whereas std::make_pair will create a pair with the type of the elements that are passed to it, without you needing to tell it. That’s what I could gather from various docs anyways.

    See this example from http://www.cplusplus.com/reference/std/utility/make_pair/

    pair <int,int> one;
    pair <int,int> two;
    
    one = make_pair (10,20);
    two = make_pair (10.5,'A'); // ok: implicit conversion from pair<double,char>
    

    Aside from the implicit conversion bonus of it, if you didn’t use make_pair you’d have to do

    one = pair<int,int>(10,20)
    

    every time you assigned to one, which would be annoying over time…

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

Sidebar

Related Questions

Whats the difference between std::cout<<std::setbase(8)<<32; and std::cout<<std::oct<<32; Are they equivalent? And also, what is
I have a std::vector<int> and I want serialize it. For this purpose I am
The purpose is to use C++ in a useful way. I have just started
For what purpose I should use std::get_temporary_buffer ? Standard says the following: Obtains a
Is there an easy way to parse a std::string in search of a list
#include <vector> std::vector<long int> as; long int a(size_t n){ if(n==1) return 1; if(n==2) return
I have a simple C++ program: #include <iostream> int main() { std::cout << "Hello\n";
There are convincing arguments against using namespace std , so why was it introduced
Online references have rather brief and vague descriptions on the purpose of std::iostream::sentry .
Purpose: I plan to Create a XML file with XmlTextWriter and Modify/Update some Existing

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.