|
Boost : |
From: Gabriel Dos Reis (dosreis_at_[hidden])
Date: 1999-12-09 00:36:48
jsiek_at_[hidden] writes:
[...]
| > Personally, I would prefer if there were separate functions to get the
| > respective iterator, especially as C++ misses such neat assignment
| > operations as there are in perl where you can assign to a list of
| > objects at once (well, I think there was a library for this mentioned
| > somewhere; was it Boost or have seen it in news: I don't know). Is
|
| Yes, it was posted to Boost. I like it. Here's how it would look with
| the graph interface:
|
| tie(first,last) = adj(v,g);
|
| A dumbed-down, two argument version is trivial to implement:
|
| template <class A, class B>
| class Tie
| {
| public:
| Tie(A a, B b) : first(a), second(b) { }
| template <class Pair>
| Tie& operator=(const Pair& p) {
| first = p.first;
| second = p.second;
| }
| protected:
| A first;
| B second;
| };
|
| template <class A, class B>
| Tie<A&,B&> tie(A& a, B& b) {
| return Tie<A&,B&>(a,b);
^^^^^^^^^^^^^^^^^^^^^^
I'm not sure if the synthetised copy-ctor is guaranted to do the right
thing here.
| }
Why not just
template<typename A, typename b>
class tie {
public:
tie(A& a, B& b) : first(a), second(b) {}
template<typename Pair>
tie& operator=(const Pair& p)
{
first = p.first;
second = p.second;
}
private:
A& first;
B& second;
};
That is the constructor function-call syntax does the right thing.
-- Gaby
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk