 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Joe Gottman Guest
|
Posted: Sun May 13, 2007 7:51 pm Post subject: Concepts and the "more specialized" relationship |
|
|
I just realized that there's a subtle difference between classes and
concepts that might affect the "more specialized" relationship that is
used for overload resolution. Classes use inheritance to model the "isa"
relationship.
class A {}
class B : public A {} // All B's are A's.
We can can do the same thing with concepts, although in this case it is
called refinement.
concept InputIterator<typename Iter> { }
concept ForwardIterator<typename Iter> : InputIterator<Iter> { }
//All ForwardIterators are InputIterators
However there's another, completely different way to make two concepts
model the "isa" relationship: concept_maps.
concept Range<typename R> {}
concept Container<typename C> {}
template <Container C> concept_map Range<C> { } //All Containers are
Ranges.
In this case, is the Container concept considered to be more specialized
than the Range concept for overload resolution? Can I define the
following overload set:
template <Range R> inline std::size_t size(const R &r);
template <Container C> inline std::size_t size(const C &c);
and have the second function called for all Containers and the first one
called for all Ranges that aren't Containers? If I can't do it
directly, will the following variation work?
template <Range R> inline std::size_t size(const R &r);
template <Range R> requires Container<R>
inline std::size_t size(const R &r);
Joe Gottman
---
[ 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 |
|
 |
Douglas Gregor Guest
|
Posted: Tue May 15, 2007 12:46 am Post subject: Re: Concepts and the "more specialized" relationship |
|
|
On May 13, 8:51 am, jgott...@carolina.rr.com (Joe Gottman) wrote:
| Quote: | However there's another, completely different way to make two concepts
model the "isa" relationship: concept_maps.
concept Range<typename R> {}
concept Container<typename C> {}
template <Container C> concept_map Range<C> { } //All Containers are
Ranges.
In this case, is the Container concept considered to be more specialized
than the Range concept for overload resolution?
|
Yes.
| Quote: | Can I define the following overload set:
template <Range R> inline std::size_t size(const R &r);
template <Container C> inline std::size_t size(const C &c);
and have the second function called for all Containers and the first one
called for all Ranges that aren't Containers?
|
Yes.
| Quote: | If I can't do it
directly, will the following variation work?
template <Range R> inline std::size_t size(const R &r);
template <Range R> requires Container<R
inline std::size_t size(const R &r);
|
That'll work, too.
- Doug
---
[ 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 |
|
 |
|
|
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
|
|