473,467 Members | 1,307 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

q re abstracting set operations (I'm baffled)

Hi,

I've been trying to create a set of abstract set operations, so that I
could do something like this

set1 = union(set2, set3);

or even

set1 = set2 | set3;

in a generic way (write once, instantiate for different set types), and
in a way that abstracts out the housekeeping that has to be done to use
the set algorithms in <algorithm>.

So far I'm failing. I tried passing set_union and friends as a
template parameter, but I couldn't figure out a form that would work.
So far I'm failing to even create a pointer to set_union. Any
suggestions? Is this a solved problem?
typedef set<ddvector::size_type> set_dds;

typedef set_dds::iterator setop(set_dds::iterator, set_dds::iterator,
set_dds::iterator, set_dds::iterator,
set_dds::iterator);

#if 0
// this draws an error--no idea why
setop *f = &set_intersection<set_dds, set_dds, set_dds>;
#endif

#if 0
set_dds
safe_set_op(setop *op, set_dds set1, set_dds set2) {
set_dds tmp;
// compiler doesn't seem to like inserter use here--no idea why
op(set1.begin(), set1.end(), set2.begin(), set2.end(),
inserter(tmp, tmp.begin()));
return tmp;
}
#endif

#if 0
// wanted to do something like this
set_dds
operator&(set_dds set1, set_dds set2) {
return safe_set_op(set_intersection<set_dds, set_dds, set_dds>, set1,
set2);
}
#endif

// This code cries out for abstraction, but I don't see how to do it...
set_dds
operator&(set_dds &set1, set_dds &set2) {
set_dds tmp;
set_intersection(set1.begin(), set1.end(), set2.begin(), set2.end(),
inserter(tmp, tmp.begin()));
return tmp;
}

set_dds &
operator&=(set_dds &set1, set_dds &set2) {
return set1 = set1 & set2;
}

set_dds
operator|(set_dds set1, set_dds set2) {
set_dds tmp;
set_union(set1.begin(), set1.end(), set2.begin(), set2.end(),
inserter(tmp, tmp.begin()));
return tmp;
}

set_dds &
operator|=(set_dds &set1, set_dds &set2) {
return set1 = set1 | set2;
}

May 11 '06 #1
1 1309
tu*****@gmail.com wrote:
Hi,

I've been trying to create a set of abstract set operations, so that I
could do something like this

set1 = union(set2, set3);

or even

set1 = set2 | set3;

in a generic way (write once, instantiate for different set types), and
in a way that abstracts out the housekeeping that has to be done to use
the set algorithms in <algorithm>.

So far I'm failing. I tried passing set_union and friends as a
template parameter, but I couldn't figure out a form that would work.
So far I'm failing to even create a pointer to set_union. Any
suggestions? Is this a solved problem?
typedef set<ddvector::size_type> set_dds;

typedef set_dds::iterator setop(set_dds::iterator, set_dds::iterator,
set_dds::iterator, set_dds::iterator,
set_dds::iterator);
Last parameter of setop needs to be an output iterator e.g.
insert_iterator<set_dds>.
#if 0
// this draws an error--no idea why
setop *f = &set_intersection<set_dds, set_dds, set_dds>;
#endif


set_intersection requires the types of iterators as template parameters
and the third one an output iterator in particular. So this should be
rather

setop *f = &set_intersection<set_dds::iterator, set_dds::iterator,
insert_iterator<set_dds> >;

May 11 '06 #2

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

Similar topics

15
by: Scott Auge | last post by:
I am looking for comments on something that lets me abstract database updates in an object. Lemme explain what I am thinking: Lets say I have an object Person with... SetFirstName()...
4
by: Mark Thomas | last post by:
Hi I do not understand why the following does not compile under Visual C++ 7.1. It is just a simple "Hello, World" program. // Hello World Application. Why does this fail? #include <iostream>...
13
by: s_m_b | last post by:
I'm building a suite of online forms for insurance. These have been stripped down from messy MS Word templates, and two of the six, substantially identical, are misbehaving with the .js page that...
4
by: Tim Robinson | last post by:
Hi, I generally consider myself competent with the complexities of quoting but I can't figure out postgres at all. I've read the manual and it looks very straightforward but that doesn't accord...
11
by: Full Decent | last post by:
Hey all! I've been using PHP for a while and I'm hearing that I should look into using it OO. I'm looking into making changes to the program Camera Life (http://fdcl.sf.net). I want to abstract...
36
by: mrby | last post by:
Hi, Does anyone know of any link which describes the (relative) performance of all kinds of C operations? e.g: how fast is "add" comparing with "multiplication" on a typical machine. Thanks!...
3
by: Hallvard B Furuseth | last post by:
I'm wondering how to design this: An API to let a request/response LDAP server be configured so a user-defined Python module can handle and/or modify some or all incoming operations, and later...
17
by: sheldonlg | last post by:
I need to do some modifications on some code I just inherited and that code has me baffled. On one page, caller.php, with method get there is an anchor with href="foo.php?bar=123". On foo.php,...
0
by: tabassumpatil | last post by:
Please send the c code for: 1.STACK OPERATIONS : Transfer the names stored in stack s1 to stack s2 and print the contents of stack s2. 2.QUEUE OPERATIONS : Write a program to implement...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
1
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...
0
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,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.