T
tutufan
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;
}
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;
}