Consider the following program:
#include <cstdlib>
#include <iostream>
#include <set>
#include <map>
#include <algorithm>
#include <iterator>
#include <utility>
using namespace std;
int main()
{
typedef pair<int, intp_type;
multiset<p_type c1;
c1.insert(make_ pair(0, 2));
c1.insert(make_ pair(0, 0));
c1.insert(make_ pair(0, 1));
c1.insert(make_ pair(2, 3));
multimap<int, intc3;
c3.insert(make_ pair(5, 0));
c3.insert(make_ pair(0, 0));
c3.insert(make_ pair(3, 2));
c3.insert(make_ pair(0, -1));
c3.insert(make_ pair(1, -1));
multimap<int, intdest;
merge(c1.begin( ), c1.end(), c3.begin(), c3.end(),
inserter(dest, dest.begin()));
return EXIT_SUCCESS;
}
Suppose the above program is named z.cpp and is compiled as
g++ -std=c++98 -pedantic -Wall -Wextra z.cpp
Then I get compilation error for the line
merge(...)
z.cpp:32: instantiated from here
/usr/lib/gcc/i386-redhat-linux/3.4.3/../../../../include/c++/3.4.3/
bits/stl_algo.h:2979 : error: no match for 'operator<' in '(&__first2)-
>std::_Rb_tree_ iterator<_Tp>:: operator* [with _Tp = std::pair<const
int, int>]() < (&__first1)-
>std::_Rb_tree_ const_iterator< _Tp>::operator* [with _Tp =
main()::p_type]()'
Kindly help me to fix this compilation error.
Thanks
V.Subramanian 3 2409 su************* *@yahoo.com, India wrote:
Consider the following program:
#include <cstdlib>
#include <iostream>
#include <set>
#include <map>
#include <algorithm>
#include <iterator>
#include <utility>
using namespace std;
int main()
{
typedef pair<int, intp_type;
multiset<p_type c1;
c1.insert(make_ pair(0, 2));
c1.insert(make_ pair(0, 0));
c1.insert(make_ pair(0, 1));
c1.insert(make_ pair(2, 3));
multimap<int, intc3;
c3.insert(make_ pair(5, 0));
c3.insert(make_ pair(0, 0));
c3.insert(make_ pair(3, 2));
c3.insert(make_ pair(0, -1));
c3.insert(make_ pair(1, -1));
multimap<int, intdest;
merge(c1.begin( ), c1.end(), c3.begin(), c3.end(),
inserter(dest, dest.begin()));
return EXIT_SUCCESS;
}
Suppose the above program is named z.cpp and is compiled as
g++ -std=c++98 -pedantic -Wall -Wextra z.cpp
Then I get compilation error for the line
merge(...)
z.cpp:32: instantiated from here
/usr/lib/gcc/i386-redhat-linux/3.4.3/../../../../include/c++/3.4.3/
bits/stl_algo.h:2979 : error: no match for 'operator<' in '(&__first2)-
>std::_Rb_tree_ iterator<_Tp>:: operator* [with _Tp = std::pair<const
int, int>]() < (&__first1)-
>std::_Rb_tree_ const_iterator< _Tp>::operator* [with _Tp =
main()::p_type]()'
Kindly help me to fix this compilation error.
typeof "multiset<p_typ e>::value_type " == p_type == pair<int, int... Type1
typeof "multimap<i nt, int>::value_typ e" == pair<const int, int ... Type2
Type1. Type2 are two different specialization of template class pair
so there are no specialization of
template <class T1, class T2>
bool operator<(const pair<T1, T2>& x, const pair<T1, T2>& y);
while the 5-arg merge needs operator<
take a look at the implementation of merge.
--
Best Regards
Barry
Barry wrote:
su************* *@yahoo.com, India wrote:
>Consider the following program:
#include <cstdlib> #include <iostream> #include <set> #include <map> #include <algorithm> #include <iterator> #include <utility>
using namespace std;
int main() { typedef pair<int, intp_type;
multiset<p_type c1;
c1.insert(make_ pair(0, 2)); c1.insert(make_ pair(0, 0)); c1.insert(make_ pair(0, 1)); c1.insert(make_ pair(2, 3));
multimap<int, intc3;
c3.insert(make_ pair(5, 0)); c3.insert(make_ pair(0, 0)); c3.insert(make_ pair(3, 2)); c3.insert(make_ pair(0, -1)); c3.insert(make_ pair(1, -1));
multimap<int, intdest;
merge(c1.begin( ), c1.end(), c3.begin(), c3.end(), inserter(des t, dest.begin()));
return EXIT_SUCCESS; }
Suppose the above program is named z.cpp and is compiled as g++ -std=c++98 -pedantic -Wall -Wextra z.cpp
Then I get compilation error for the line merge(...)
z.cpp:32: instantiated from here /usr/lib/gcc/i386-redhat-linux/3.4.3/../../../../include/c++/3.4.3/ bits/stl_algo.h:2979 : error: no match for 'operator<' in '(&__first2)-
>>std::_Rb_tree _iterator<_Tp>: :operator* [with _Tp = std::pair<const
int, int>]() < (&__first1)-
>>std::_Rb_tree _const_iterator <_Tp>::operator * [with _Tp =
main()::p_ty pe]()'
Kindly help me to fix this compilation error.
typeof "multiset<p_typ e>::value_type " == p_type == pair<int, int... Type1
typeof "multimap<i nt, int>::value_typ e" == pair<const int, int ... Type2
Type1. Type2 are two different specialization of template class pair
so there are no specialization of
template <class T1, class T2>
bool operator<(const pair<T1, T2>& x, const pair<T1, T2>& y);
while the 5-arg merge needs operator<
take a look at the implementation of merge.
"merge" also requires the two value_type to be the same type.
--
Best Regards
Barry su************* *@yahoo.com, India wrote:
int main()
{
typedef pair<int, intp_type;
multiset<p_type c1;
c1.insert(make_ pair(0, 2));
c1.insert(make_ pair(0, 0));
c1.insert(make_ pair(0, 1));
c1.insert(make_ pair(2, 3));
multimap<int, intc3;
c3.insert(make_ pair(5, 0));
c3.insert(make_ pair(0, 0));
c3.insert(make_ pair(3, 2));
c3.insert(make_ pair(0, -1));
c3.insert(make_ pair(1, -1));
multimap<int, intdest;
merge(c1.begin( ), c1.end(), c3.begin(), c3.end(),
inserter(dest, dest.begin()));
return EXIT_SUCCESS;
}
[...]
z.cpp:32: instantiated from here
/usr/lib/gcc/i386-redhat-linux/3.4.3/../../../../include/c++/3.4.3/
bits/stl_algo.h:2979 : error: no match for 'operator<' in '(&__first2)-
>std::_Rb_tree_ iterator<_Tp>:: operator* [with _Tp = std::pair<const
int, int>]() < (&__first1)-
>std::_Rb_tree_ const_iterator< _Tp>::operator* [with _Tp =
main()::p_type]()'
The value type of your multimap is actually std::pair<const int, int>.
However, std::pair<const int, intand std::pair<int, intare unrelated
types. The basic problem of type incompatibility can be illustrated by a
simpler example:
#include <utility>
int main()
{
std::pair<const int, inta;
std::pair<int, intb;
a < b; // error
}
Depending on how big your containers really are and how often that piece
of code is executed, a viable solution may be copying your
std::pair<const int, intelements from the multimap into a new range of
std::pair<int, intand use that one in std::merge.
--
Christian Hackl This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Hunter Hou |
last post by:
Folks,
I am just curious why standard library doesn't provide a "merge" operation
without sorting, because sometimes I don't require sorting, just merge.
I looked at list.merge() and merge() algorithm, both require sorted
sequenece.
Thanks,
Hunter
|
by: tuko |
last post by:
Hello kind people.
The folliowing code gives me a compilation error, under
MSVC 6.0 and intel 8.0 compiler. It compiles fine with
g++ 3.3.1 and borland 5.5
Can you tell me please if the code is correct?.
If the code is correct do you know any tip
to "circumvent" the compilation error?
|
by: Volkan Karaboða |
last post by:
I have an aspx that contains a report prepared with crystal report,
when I try to run myapp. on another server which has no crystal report tool
installed on it.
I receive following error code even I copid crystal's dll files bin
directory of myapp.
Error:"CrystalDecisions.CrystalReports.Engine.InternalException: Cannot find
KeycodeV2.dll, or invalid keycode."
What is the matter?? Could you help me please!
|
by: ilikesluts |
last post by:
Hi Group,
I'm new to XML, here is my question:
Would it be possible to write an algorithm that takes in two XML
documents with the only condition being that they have the same root
element? If it is possible what would be the best technology to
implement the solution (XMLDom, XSLT...)? How hard would the solution
be?
|
by: rkk |
last post by:
Hi,
I have written a generic mergesort program which is as below:
---------------------------------------------------------
mergesort.h
-----------------------
void
MergeSort(void *array,int p,int r,int elemSize,int(*Compare)(const
void *keyA,const void *keyB));
| |
by: Adrian Hawryluk |
last post by:
I'm implementing an algorithm that will fill a container with the same
item. However, my object creation function isn't working correctly.
This should auto detect the types based on the parameters it was passed.
But I must be missing something as it will not compile.
template<typename dest_t, typename src_t>
inline fill<dest_t, src_tmake_fill(dest_t& dest, src_t& src) //< error
{
return fill<dest_t, src_t>(src);
}
|
by: subramanian100in |
last post by:
Consider the following program:
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
using namespace std;
|
by: vekka |
last post by:
Hi!
Could someone please help me to understand the use of merge algorithm(conceptually) with linked lists. What I want to do in the linked list function is:
the function gets two inputs, i.e the pointers to the two smaller lists, then the function should able to merge these two together, and then return the head-pointer to this merged list. What happens in my case, is that I "lose" data when running it . My result is like this:
Even OR...
|
by: subramanian100in |
last post by:
consider :
template<class InIt1, class InIt2, class OutIt>
OutIt merge(InIt1 first1, InIt1 last1, InIt2 first2, InIt2 last2,
OutIt dest);
Can the destination container already contain some elements ? If so,
will they also be taken into account for doing the sorting and
merging ? Or, should the destination container have just enough space
to hold the result of the merge( that is, it should not contain any
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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: 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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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...
| |