C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Class with member swap and std::swap specialization still no
Goto page 1, 2  Next
 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
Niels Dekker (no reply ad
Guest





PostPosted: Wed Sep 13, 2006 7:39 am    Post subject: Class with member swap and std::swap specialization still no Reply with quote



Does the following class meet the Swappable requirement, according to
C++0x? It has a public swap member function and a specialization of
std::swap.

#include <algorithm>

class Uncopyable
{
public:
Uncopyable() {}
void swap(Uncopyable &) {}
private:
Uncopyable(const Uncopyable &);
Uncopyable& operator=(const Uncopyable&);
};

namespace std
{
template <>
void swap<Uncopyable>(Uncopyable& lhs, Uncopyable & rhs)
{
lhs.swap(rhs);
}
}

If I understand the Draft well, this class is not Swappable. Which
sounds rather counter-intuitive to me!
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1905.pdf

Wouldn't it better to include any T as being Swappable for which the
following lines are valid, and have the right semantics?
using std::swap;
swap(t, u); // t and u are values of type T

This corresponds to the way Scott Meyers recommands calling a swap
function, in Effective C++, 3rd Edition, item 25.


Kind regards,

Niels Dekker
www.xs4all.nl/~nd/dekkerware

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
Greg Herlihy
Guest





PostPosted: Wed Sep 13, 2006 7:39 am    Post subject: Re: Class with member swap and std::swap specialization stil Reply with quote



"Niels Dekker no reply address wrote:
Quote:
Does the following class meet the Swappable requirement, according to
C++0x? It has a public swap member function and a specialization of
std::swap.

#include <algorithm

class Uncopyable
{
public:
Uncopyable() {}
void swap(Uncopyable &) {}
private:
Uncopyable(const Uncopyable &);
Uncopyable& operator=(const Uncopyable&);
};

namespace std
{
template
void swap<Uncopyable>(Uncopyable& lhs, Uncopyable & rhs)
{
lhs.swap(rhs);
}
}

If I understand the Draft well, this class is not Swappable. Which
sounds rather counter-intuitive to me!
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1905.pdf

Wouldn't it better to include any T as being Swappable for which the
following lines are valid, and have the right semantics?
using std::swap;
swap(t, u); // t and u are values of type T

No, the second line all by itself should be valid:

swap( t, u );

which is not the case in the above program. Because swap() has been
defined in the std namespace, it will not be found when passed
arguments of a class (Uncopyable) that has been declared in the global
namespace.

The fix therefore is to declare swap() in the same namespace as the one
in which Uncopyable is declared - whether that namespace is, as in this
case, the global namespace, or whether it is some other namespace that
the program has declared:

void swap(Uncopyable& lhs, Uncopyable & rhs)
{
lhs.swap(rhs);
}

Greg

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
Niels Dekker (no reply ad
Guest





PostPosted: Wed Sep 13, 2006 5:26 pm    Post subject: Re: Class with member swap and std::swap specialization stil Reply with quote



Quote:
Wouldn't it better to include any T as being Swappable for which the
following lines are valid, and have the right semantics?
using std::swap;
swap(t, u); // t and u are values of type T

Greg Herlihy replied:
Quote:

No, the second line all by itself should be valid:

swap( t, u );

which is not the case in the above program. Because swap() has been
defined in the std namespace, it will not be found when passed
arguments of a class (Uncopyable) that has been declared in the global
namespace.

Thank you. So will std functions that have those Swappable requirements
(e.g., std::iter_swap) give compile errors when I try to use them for
objects of my Uncopyable class, even if it has a specialization for
std::swap?

In other words, will the following program be rejected by C++0x?
------------------------------------------------------------------------
#include <algorithm>

class Uncopyable
{
public:
Uncopyable() {}
void swap(Uncopyable &) {}
private:
Uncopyable(const Uncopyable &);
Uncopyable& operator=(const Uncopyable&);
};

namespace std
{
template <>
void swap<Uncopyable>(Uncopyable& lhs, Uncopyable & rhs)
{
lhs.swap(rhs);
}
}

int main()
{
Uncopyable t, u;

std::iter_swap(&t, &u); // Rejected by C++0x?
}
------------------------------------------------------------------------

Kind regards,

Niels Dekker

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
Howard Hinnant
Guest





PostPosted: Wed Sep 13, 2006 5:29 pm    Post subject: Re: Class with member swap and std::swap specialization stil Reply with quote

In article <45072852.3A818711 (AT) this (DOT) is.invalid>,
unknown (AT) this (DOT) is.invalid ("Niels Dekker (no reply address)") wrote:

Quote:
Does the following class meet the Swappable requirement, according to
C++0x? It has a public swap member function and a specialization of
std::swap.

#include <algorithm

class Uncopyable
{
public:
Uncopyable() {}
void swap(Uncopyable &) {}
private:
Uncopyable(const Uncopyable &);
Uncopyable& operator=(const Uncopyable&);
};

namespace std
{
template
void swap<Uncopyable>(Uncopyable& lhs, Uncopyable & rhs)
{
lhs.swap(rhs);
}
}

If I understand the Draft well, this class is not Swappable. Which
sounds rather counter-intuitive to me!
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1905.pdf

Wouldn't it better to include any T as being Swappable for which the
following lines are valid, and have the right semantics?
using std::swap;
swap(t, u); // t and u are values of type T

This corresponds to the way Scott Meyers recommands calling a swap
function, in Effective C++, 3rd Edition, item 25.

Thanks Niels. I think you make a good point. I've opened LWG issue 594.

-Howard

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
Greg Herlihy
Guest





PostPosted: Wed Sep 13, 2006 6:36 pm    Post subject: Re: Class with member swap and std::swap specialization stil Reply with quote

Niels Dekker (no reply address) wrote:
Quote:
Wouldn't it better to include any T as being Swappable for which the
following lines are valid, and have the right semantics?
using std::swap;
swap(t, u); // t and u are values of type T

Greg Herlihy replied:

No, the second line all by itself should be valid:

swap( t, u );

which is not the case in the above program. Because swap() has been
defined in the std namespace, it will not be found when passed
arguments of a class (Uncopyable) that has been declared in the global
namespace.

Thank you. So will std functions that have those Swappable requirements
(e.g., std::iter_swap) give compile errors when I try to use them for
objects of my Uncopyable class, even if it has a specialization for
std::swap?

Even when a program fails to meet the Swappable requirement for a given
operation, it may still compile and even run as expected. There is just
no assurance - the code could compile but not work as expected. And it
is this kind of "silent failure" that is the real risk for not meeting
the requirements (see below).

Quote:
In other words, will the following program be rejected by C++0x?
------------------------------------------------------------------------
#include <algorithm

class Uncopyable
{
public:
Uncopyable() {}
void swap(Uncopyable &) {}
private:
Uncopyable(const Uncopyable &);
Uncopyable& operator=(const Uncopyable&);
};

namespace std
{
template
void swap<Uncopyable>(Uncopyable& lhs, Uncopyable & rhs)
{
lhs.swap(rhs);
}
}

int main()
{
Uncopyable t, u;

std::iter_swap(&t, &u); // Rejected by C++0x?
}

No, the code will compile and run as expected even though Uncopyable
has not met the Swappable requirements. However the results could well
be different if an (otherwise unrelated) swap() routine is declared in
the global namespace.

void swap(Uncopyable& lhs, Uncopyable& rhs)
{
// do nothing interesting
}

Now all calls to swap() that used to call the Uncopyable specialization
in the std namespace are now dispatched to this global swap() routine -
even though this routine does not meet the Swappable requirements. So
although the program will still compile and run - the addition of this
new routine means that it will no longer produce the expected results.

Whereas if the program had declared the required swap() routine in the
appropriate (that is, global) namespace to begin with - then this
unfortunate situation would have been avoided.

Greg

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
Jens Theisen
Guest





PostPosted: Wed Sep 13, 2006 7:54 pm    Post subject: Re: Class with member swap and std::swap specialization stil Reply with quote

"Greg Herlihy" <greghe (AT) pacbell (DOT) net> writes:

Quote:
Wouldn't it better to include any T as being Swappable for which the
following lines are valid, and have the right semantics?
using std::swap;
swap(t, u); // t and u are values of type T

This recommendation is there in case you can't be sure that t and u
are not defined in the global namespace - there nothing will be found
by ADL. Stuff in you namespaces and namespace std are fine.

Jens

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
Niels Dekker (no reply ad
Guest





PostPosted: Fri Sep 15, 2006 2:33 am    Post subject: Is a Swappable class allowed to throw an exception? Reply with quote

Howard Hinnant wrote:
Quote:
Thanks Niels. I think you make a good point. I've opened LWG issue 594.

Thank you, Howard! Hopefully providing an appropriate specialization of
std::swap will be sufficient to make a class Swappable in C++0x...

Yet another Swappable question, though. Is it allowed for a Swappable
class to throw an exception, while swapping?

For example, my BadCopier class (see below) throws a bad_alloc in its
copy constructor, as well as in its assignment operator, but still it is
both CopyConstructible and Assignable, or not? So is it Swappable?

My BadSwapper class (further below) throws a bad_alloc whenever its swap
function is called. Still... is it Swappable as well? I doubt it, as
it doesn't meet the post-condition for swap(t, u), as described in the
Draft, Table 32, Swappable requirements:
"t has the value originally held by u, and u has the value originally
held by t."

(Draft: www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1905.pdf)

Here are my "bad" classes:
------------------------------------------------------------------------
class BadCopier
{
int m_data;
public:
explicit BadCopier(int arg = 0): m_data(arg) {}

BadCopier(const BadCopier& rhs): m_data(rhs.m_data)
{
throw std::bad_alloc();
}
BadCopier & operator=(const BadCopier& rhs)
{
m_data = rhs.m_data;
throw std::bad_alloc();
}
};

class BadSwapper
{
int m_data;
public:
explicit BadSwapper(int arg = 0): m_data(arg) {}

friend void swap(BadSwapper& lhs, BadSwapper& rhs)
{
std::swap(lhs.m_data, rhs.m_data);
throw std::bad_alloc();
}
};
------------------------------------------------------------------------
Please let me know if both classes satisfy the Swappable requirements!


Kind regards,

Niels Dekker

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
Howard Hinnant
Guest





PostPosted: Fri Sep 15, 2006 3:22 am    Post subject: Re: Is a Swappable class allowed to throw an exception? Reply with quote

In article <4509C736.7EC6301C (AT) this (DOT) is.invalid>,
unknown (AT) this (DOT) is.invalid ("Niels Dekker (no reply address)") wrote:

Quote:
Yet another Swappable question, though. Is it allowed for a Swappable
class to throw an exception, while swapping?

You raise good points. I believe the current WD says that you can throw
while swapping. The current CopyConstructible requirement has similar
wording to the Swappable requirement, and clearly a copy constructor can
throw.

That being said, a personal coding guideline of mine is that none of
swap, move constructor or move assignment should throw. Bad things
happen. But at this point that's more of a coding guideline than a
standards requirement, and should probably stay that way. Caveat: I have
proposed a corner or two that do require a nothrow move constructor,
e.g.:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1858.html

23.2.4.2 - vector capacity

It amazes me how often a throwing swap or move actually turns out ok
(for a sufficiently lax definition of ok). But on some primeval level,
such things scare me, much like rattle snakes do. Yes, they can be
handled safely. I'm glad other people do that so I don't have to. :-)

-Howard

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
Pete Becker
Guest





PostPosted: Fri Sep 15, 2006 4:08 am    Post subject: Re: Is a Swappable class allowed to throw an exception? Reply with quote

Howard Hinnant wrote:
Quote:

That being said, a personal coding guideline of mine is that none of
swap, move constructor or move assignment should throw.

On the other hand, this precludes a small-object optimization for
std::tr1::function. If its swap member function is allowed to throw
exceptions then it can hold small function objects internally rather
than putting them on the free store.

--

-- Pete

Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." For more information about this book, see
www.petebecker.com/tr1book.

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
Howard Hinnant
Guest





PostPosted: Fri Sep 15, 2006 9:10 am    Post subject: Re: Is a Swappable class allowed to throw an exception? Reply with quote

In article <hdWdnTOHHPquQpTYnZ2dnUVZ_omdnZ2d (AT) giganews (DOT) com>,
petebecker (AT) acm (DOT) org (Pete Becker) wrote:

Quote:
That being said, a personal coding guideline of mine is that none of
swap, move constructor or move assignment should throw.

On the other hand, this precludes a small-object optimization for
std::tr1::function. If its swap member function is allowed to throw
exceptions then it can hold small function objects internally rather
than putting them on the free store.

<nod> std::tr1::function is a subject I've been worrying a lot about
lately for a variety of reasons.

In the sso optimizations I've done to date for std::function I restrict
the sso to function pointers and empty function objects. Admittedly
that doesn't restrict empty function objects from throwing on swap, but
it does make it "6-nines" unlikely. And it also allows the sso
optimization for a vast majority of use cases.

But this is a very interesting standards question: How much of this
should be QOI, and how much should be standard?

Fwiw the other area that std::function concerns me is: Does
std::function(F) require F to be CopyConstructible?

I believe it does today. And I'm not happy with that answer. I haven't
come up with a good way to say no to requiring CopyConstructible of F
yet. Perhaps concepts will lend a hand...

-Howard

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
Pete Becker
Guest





PostPosted: Fri Sep 15, 2006 10:52 pm    Post subject: Re: Is a Swappable class allowed to throw an exception? Reply with quote

Howard Hinnant wrote:
Quote:

In the sso optimizations I've done to date for std::function I restrict
the sso to function pointers and empty function objects. Admittedly
that doesn't restrict empty function objects from throwing on swap, but
it does make it "6-nines" unlikely. And it also allows the sso
optimization for a vast majority of use cases.


Doug Gregor mentioned to me a few months ago that he was re-implementing
function, and decided to ignore the possibility that copying a callable
object (note switch to TR1 terminology <g>) might throw an exception. In
my opinion that's exactly right: you don't impose constraints for fringe
cases at the expense of making the mainline harder, bigger, or slower. I
wouldn't call this 6-nines, because that implies statistical data that
almost certainly doesn't exist. Besides, that's too extreme. The best
rule is that almost everything works as advertised, and the cases that
don't are easy to recognize. The more sophisticated the implementation
gets, the harder it is to describe the cases it can't handle.

My analogy is the old through-the-lens metering systems on cameras. They
looked at the overall brightness of the image, and set the exposure to
get a mid-tone. That got 90% of most people's pictures right. If the
subject was backlit (background brighter than subject) that would
produce a picture that was underexposed, and you had to override the
automatic setting to give more exposure. If the background was dark, the
picture would be overexposed, and you had to override the other way.
Then they (Nikon, I think) came out with fancier exposure systems that
looked at five different areas of the image, to get better exposures in
some cases. They got 95% right, but you could no longer just look at the
scene to figure out what whether the exposure would be right or whether
you had to override the automatic setting. Of course, today you get
instant feedback, so you can adjust after you take the first shot. But
that's hacking.

--

-- Pete

Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." For more information about this book, see
www.petebecker.com/tr1book.

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
Niels Dekker (no reply ad
Guest





PostPosted: Sun Sep 17, 2006 6:22 am    Post subject: Re: Is a Swappable class allowed to throw an exception? Reply with quote

Pete Becker wrote:
Quote:
On the other hand, this precludes a small-object optimization for
std::tr1::function. If its swap member function is allowed to throw
exceptions then it can hold small function objects internally rather
than putting them on the free store.

I'm sorry I'm not yet familiar with either std::tr1::function, or
small-object optimization. Can you please explain in more detail why
std::tr1::function or any class with small-object optimization would
need to have a throwing swap?


Kind regards,

Niels Dekker

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
Niels Dekker (no reply ad
Guest





PostPosted: Sun Sep 24, 2006 11:26 pm    Post subject: What if an exception is thrown while swapping Swappable obje Reply with quote

When objects of a Swappable class are being swapped, it is allowed for
the swap function to throw an exception, according to the Draft
(N1905). This was confirmed by both Howard Hinnant and Pete Becker, in
a previous discussion, "Is a Swappable class allowed to throw an
exception?". Thanks for your replies, sofar! My next question, though:
how will std functions that impose Swappable requirements onto their
arguments cope with a throwing swap?

For example, suppose the swap function called by swap_ranges might throw
an exception. Typically this would result in having the two ranges only
partially swapped. (Which might mean user data getting corrupted!)
Does the caller have a way to tell how much of its ranges has been
swapped successfully, after calling swap_ranges? Is swap_ranges allowed
to catch the exception thrown by the swap function, and return the value
of the iterator, pointing at where it went wrong?

In other words, is the following implementation of std::swap_ranges
conforming to the Draft?

template<class ForwardIterator1, class ForwardIterator2>
ForwardIterator2
swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2)
{
while (first1 != last1)
{
try
{
swap(*first1, *first2);
}
catch(...)
{
return first2;
}
++first1;
++first2;
}
return first2;
}


Kind regards,

Niels Dekker

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
David Abrahams
Guest





PostPosted: Mon Sep 25, 2006 9:42 pm    Post subject: Re: What if an exception is thrown while swapping Swappable Reply with quote

unknown (AT) this (DOT) is.invalid ("Niels Dekker (no reply address)") writes:

Quote:
When objects of a Swappable class are being swapped, it is allowed for
the swap function to throw an exception, according to the Draft
(N1905). This was confirmed by both Howard Hinnant and Pete Becker, in
a previous discussion, "Is a Swappable class allowed to throw an
exception?". Thanks for your replies, sofar! My next question, though:
how will std functions that impose Swappable requirements onto their
arguments cope with a throwing swap?

The same way they deal today with element copies throwing during sort,
swap_ranges, etc.

Quote:
For example, suppose the swap function called by swap_ranges might throw
an exception. Typically this would result in having the two ranges only
partially swapped. (Which might mean user data getting corrupted!)

The standard library only maintains (and can only maintain) the
invariants that are visible to it. Users are responsible for
maintaining their own invariants. If being "uncorrupted" according to
some higher-level user invariant depends on the ranges either being
fully swapped or fully unswapped, it's the user's job to ensure that.

Quote:
Does the caller have a way to tell how much of its ranges has been
swapped successfully, after calling swap_ranges?

No. And what would the caller do with that information anyway? Any
attempt to unswap the swapped parts could throw, too.

Quote:
Is swap_ranges allowed to catch the exception thrown by the swap
function, and return the value of the iterator, pointing at where it
went wrong?

No. I don't think it's explicitly stated anywhere, but standard
library algorithms are intended to be exception-neutral.

--
Dave Abrahams
Boost Consulting
www.boost-consulting.com

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
Niels Dekker (no reply ad
Guest





PostPosted: Wed Sep 27, 2006 9:10 am    Post subject: Swappable base class, unswappable derived class, undefined b Reply with quote

Thanks to David Abrahams, for clearly answering the questions of my
previous posting, "What if an exception is thrown while swapping
Swappable objects?"

Now suppose a base class is Swappable (according to the Draft), because
it has a swap function. Does this automatically make a class that is
publicly derived from this base class Swappable as well?

Example:
#include <algorithm>

class Base // This class is surely Swappable
{
friend void swap(Base& lhs, Base& rhs)
{
std::swap(lhs.m_data, rhs.m_data);
}
public:
explicit Base(int arg=0): m_data(arg)
{
}
protected:
int m_data;
};

class Derived: public Base // Is Derived Swappable as well?
{
public:
explicit Derived(int arg1=0, int arg2=0): Base(arg1), m_const(arg2)
{
}
protected:
const int m_const;
};


My feeling is that the Derived class is not Swappable. Because although
the call swap(t, u) is valid for Derived objects t and u, it
certainly does not fulfill the postcondition described in Table 33 of
the Draft (N2009):
"t has the value originally held by u, and u has the value originally
held by t"

So it's not allowed to call std functions that impose Swappable
requirements onto their arguments, for this Derived class. E.g., the
following call to iter_swap is incorrect:

int main()
{
Derived t(22, 44), u(66, 8Cool;

std::iter_swap(&t, &u); // Violating the Swappable requirement!?!
}

Is this little program well defined in C++0x? Should the compiler issue
an error? Is the compiler allowed to do so? Or does it result in
undefined behaviour?

Kind regards,

Niels Dekker

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.