473,598 Members | 2,916 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing different sort methods to multiset

I'm trying to use an object in two different multiset containers, each
with it's own sort method. For the most frequently used, I overrode
the operator< method in the class, and for the second I wrote a method
LocationSort(). I can't seem to arrive upon the correct syntax for
defining a multiset that will use LocationSort.

multiset<DotObj ect,DotObject:: LocationSort> mySet;

fails.

Is there a correct way to do this while keeping LocationSort inside of
my class? I know I could wrap it in a separate structure and pass in
the structure name, but would prefer to keep it inside the class code
for ease-of-maintenance reasons.

Thanks.

Dale

Jan 3 '06 #1
5 2415
"Dale Marchand" <da***********@ gmail.com> schrieb im Newsbeitrag
news:11******** *************@g 43g2000cwa.goog legroups.com...
I'm trying to use an object in two different multiset containers, each
with it's own sort method. For the most frequently used, I overrode
the operator< method in the class, and for the second I wrote a method
LocationSort(). I can't seem to arrive upon the correct syntax for
defining a multiset that will use LocationSort.

multiset<DotObj ect,DotObject:: LocationSort> mySet;

fails.

Is there a correct way to do this while keeping LocationSort inside of
my class? I know I could wrap it in a separate structure and pass in
the structure name, but would prefer to keep it inside the class code
for ease-of-maintenance reasons.


Try to make LocationSort a static member function (with two parameters) of
DotObject. If that doesn't work (I didn't try it), you can still make a
separate struct/class. Such a struct can be defined inside the DotObject
class, like

class DotObject
{
public:
struct LocationSort
{
bool operator()(DotO bject const& lhs, DotObject const& rhs)
const
{
return ...
}
};
...
};

HTH
Heinz
Jan 3 '06 #2
Thanks. I just hit upon option 2 about 10 seconds prior to reading
your post (no, really I did!). It works fine....I'd just think there'd
be a simpler, more elegent way.

I'd prefer to stay away from static members, just because I've got a
bunch of threads running and prefer to stay away from the synch hassles
that static's bring.

Thanks.

Dale

Jan 3 '06 #3
On 3 Jan 2006 13:11:24 -0800 in comp.lang.c++, "Dale Marchand"
<da***********@ gmail.com> wrote,
I'd just think there'd be a simpler, more elegent way.
I'd prefer to stay away from static members
The compare function is called with two arguments, and not as a
member function. If you want to use a member function, you can wrap
it in a std::mem_fun() adapter. See Stroustrup chap. 18.4.4.2
just because I've got a
bunch of threads running and prefer to stay away from the synch hassles
that static's bring.


No reason a static member _function_ (without any local static
variables etc.) should cause a problem.

Jan 3 '06 #4
I read your reference on mem_fun, and it looks like I'm limited to 1
arg member functions at most. Since the Compare function requires 2
args, I don't see how I can use that, unless I'm missing something?

Jan 4 '06 #5
On 4 Jan 2006 10:31:43 -0800 in comp.lang.c++, "Dale Marchand"
<da***********@ gmail.com> wrote,
I read your reference on mem_fun, and it looks like I'm limited to 1
arg member functions at most. Since the Compare function requires 2
args, I don't see how I can use that, unless I'm missing something?


What you are missing is that in a member function, the object upon
which the function is invoked is equivalent to another argument.
Foo.memfun(Bar) and nonmemfun(Foo, Bar) have effectively the same
number of arguments.

Jan 6 '06 #6

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

Similar topics

4
13073
by: John MacIntyre | last post by:
Hi, I have a page with a series of child pages loaded into an iframe. When I move from page to page, I store an object containing the child's control data in a variable on the main page, then use that data to populate the controls when the child page is opened again. One of these objects contains an Array, and the page reloads fine using myArray, myArray, etc... But when I try perform some array methods on it (i.e.slice) ... it does...
14
2731
by: Alex Vinokur | last post by:
Here is some function that detects if a vector contains only different elements bool vector_contains_only_different_elements (const vector<int>& v) { for (int i = 0; i < v.size(); i++) { if (count (v.begin() + i + 1, v.end(), v) >= 1) return false; } return true; }
10
2904
by: Arthur J. O'Dwyer | last post by:
I'm seeing a bug at the moment that I can't track down. It's part of a moderately large program, but here is a small program that exhibits the bug on gcc. (The program code follows at the bottom of the message.) The symptom is this: % g++ --version g++ (GCC) 3.2.1 % g++ -W -Wall -pedantic test.cpp
3
1494
by: John Harrison | last post by:
If you insert equal values into a multiset is it specified what order they will have in the multiset. For instance, what should be the output of this program, is it defined? #include <set> #include <iostream> int main() { std::multiset<int> m;
3
4745
by: Simon Harvey | last post by:
Hi, In my application I get lots of different sorts of information from databases. As such, a lot of information is stored in DataSets and DataTable objects. Up until now, I have been passing around chunks of data in DataTables/DataSets, simply because that was the format that they were in when the data was taken from the database. Now, I know this maybe a pretty silly question with a standard "it depends" answer, but I'm going to...
25
5041
by: Stuart Hilditch | last post by:
Hi all, I am hoping that someone with some experience developing nTier apps can give me some advice here. I am writing an nTier web app that began with a Data Access Layer (DAL), Business Logic Layer (BLL) and User Interface Layer (UIL). The problem I found with this was circular referencing...
2
2174
by: =?iso-8859-1?q?Jo=E3o_Correia?= | last post by:
class CScore { public: int L; int C; CScore(int l, int c) { L = l; C = c;
9
3364
by: neil.johnston | last post by:
I have a cut down example program that uses multiset to order some data. The data arrives from various sources and has a time stamp, data with identical timestamps can arrive and due to fifo's and block sizes data from one source with a later time stamp may arrive before data from another source with and earlier time stamp. Looking at the STL i thought multiset was just the job for this. The idea was to set a window of x seconds and read...
3
2286
by: orzeech | last post by:
Hi everyone! I have a following problem: #include<iostream> #include<set> using namespace std;
0
7981
marktang
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...
0
8284
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
8392
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
8046
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
6711
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...
1
5847
isladogs
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...
0
3894
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3938
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2410
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.