473,788 Members | 2,787 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pair and make_pair

in the stl map class I see the use of a function pair and make_pair.
What is the difference between pair and make_pair?

dictionary.inse rt(std::pair<Ke y, Value>(k,v));
works as well as:

dictionary.inse rt(std::make_pa ir<Key, Value>(k,v));


Jul 22 '05 #1
3 14029
"JustSomeGu y" <no**@nottellin g.com> wrote in message
news:MwLGc.9730 59$Pk3.272416@p d7tw1no...
in the stl map class I see the use of a function pair
'std::pair' is not a function, it's a type.
and make_pair.
What is the difference between pair and make_pair?
'std::pair' is a type, 'std::make_pair ' is a function.
dictionary.inse rt(std::pair<Ke y, Value>(k,v));
works as well as:

dictionary.inse rt(std::make_pa ir<Key, Value>(k,v));

=============== =============== =============== ===============
ISO/IEC 14882:1998(E)

[....]

20.2.2 Pairs

1 The library provides a template for heterogeneous pairs of
values. The library also provides a matching template function
to simplify their construction.

template <class T1, class T2>
struct pair {
typedef T1 first_type;
typedef T2 second_type;

T1 first;
T2 second;
pair();
pair(const T1& x, const T2& y);
template<class U, class V> pair(const pair< U, V> & p);
};

[....]

template <class T1, class T2>
pair<T1, T2> make_pair(const T1& x, const T2& y);

7 Returns: pair<T1, T2>(x, y).

8 [Example: In place of:

return pair<int, double>(5, 3.1415926); // explicit types

a C++ program may contain:

return make_pair(5, 3.1415926); // types are deduced

--end example]

[....]
=============== =============== =============== ===============

-Mike
Jul 22 '05 #2
JustSomeGuy wrote:
in the stl map class I see the use of a function pair and make_pair.
What is the difference between pair and make_pair?

dictionary.inse rt(std::pair<Ke y, Value>(k,v));
works as well as:

dictionary.inse rt(std::make_pa ir<Key, Value>(k,v));


Sometimes Google is your friend:

http://www.google.com/search?hl=en&i...=Google+Search

http://www.sgi.com/tech/stl/pair.html

....
template <class T1, class T2>
pair<T1, T2> make_pair(const T1& x, const T2& x)

Equivalent to pair<T1, T2>(x, y). This is a global function, not a
member function. It exists only for the sake of convenience.
Anyhow - this means that you can write this:

make_pair(3,"s" )

instead of

pair<int, const char *>(3, "s")

because C++ will deduce template arguments of functions (but not
non-template constructors of template classes).
Jul 22 '05 #3
make_pair is an assistant function for create pair, it automatically deduce
the type of pair's two parameters.

"JustSomeGu y" <no**@nottellin g.com> дÈëÓʼþ
news:MwLGc.9730 59$Pk3.272416@p d7tw1no...
in the stl map class I see the use of a function pair and make_pair.
What is the difference between pair and make_pair?

dictionary.inse rt(std::pair<Ke y, Value>(k,v));
works as well as:

dictionary.inse rt(std::make_pa ir<Key, Value>(k,v));



Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
45869
by: Neil Zanella | last post by:
Hello, I would like to ask how come the design of C++ includes std::pair. First of all I don't think many programmers would use it. For starters, what the first and second members are depends on what you are using the pair for. For instance if I am using coordinates in two dimensional space then I like to use x and y. So I might as well define my own struct with x and y members in it and create a constructor so
6
2754
by: pmatos | last post by:
Hi all, Is there a way of (after creating a pair) set its first and second element of not? (pair is definitely a read-only struct)? Cheers, Paulo Matos
5
12087
by: ma740988 | last post by:
For starters, Happy New Year to all!! I created a vector of pairs where pair first is a primitive and pair second is a vector of ints. So now: # include <iostream> # include <vector>
11
9121
by: kietzi | last post by:
Hello world, I was wondering whether it would be possible to create a map which uses a pair of ints as key and a float as value. I have used maps with const char* as key, but have so far not been successful to use a version which uses pairs as keys. For instance, I would like to set up the map as follows: struct eqstr { bool operator()(pair<int,int> s1, pair<int,int> s2) const{
4
12255
by: onkar | last post by:
#include<iostream> using namespace std; int main(void){ const pair<const char*,const char*arr={ pair<const char*,const char*>("1","1"), pair<const char*,const char*>("12","12"), pair<const char*,const char*>("123","123"), pair<const char*,const char*>("1234","1234"), pair<const char*,const char*>("12345","12345"), };
18
2058
by: desktop | last post by:
I have made this little test with std::pair: test<intt1(1); test<intt2(2); std::pair<test<int>,test<int mypair = std::make_pair(t1,t2); where test is a template class I wrote. It seems a bit cumbersome to make a pair are there any better way to do it than the above procedure?
3
2955
by: eiji.anonremail | last post by:
Hi folks, I have a compile problem on linux, and maybe someone has an idea: #include <map> #include <iostream>
1
1621
by: subramanian100in | last post by:
consider the program: #include <cstdlib> #include <iostream> #include <utility> using namespace std; class Test {
10
3791
by: Alex Vinokur | last post by:
Hi, Is it possible to do C++-casting from const pair<const unsigned char*, size_t>* to const pair<unsigned char*, size_t>* ? Alex Vinokur
0
10366
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10173
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9967
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3674
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.