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)); 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
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).
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)); This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
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
|
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>
|
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{
|
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"),
};
| |
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?
|
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>
|
by: subramanian100in |
last post by:
consider the program:
#include <cstdlib>
#include <iostream>
#include <utility>
using namespace std;
class Test
{
|
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
|
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...
|
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...
| |
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,...
|
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |