From 8137814076974345581
X-Google-Thread: f78e5,16723f57b31f1fcb,start
X-Google-Attributes: gidf78e5,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news2.google.com!news2.google.com!newsfeed.stanford.edu!news.kjsl.com!news.alt.net!frodo.cs.rpi.edu!not-for-mail
From: SG <s.gesemann@gmail.com>
Newsgroups: comp.std.c++
Subject: C++0x concepts: Recursive constraints
Date: Sat, 18 Apr 2009 10:29:01 CST
Organization: http://groups.google.com
Lines: 56
Sender: cppmods@cs.rpi.edu
Approved: stephen.clamage@sun.com
Message-ID: <bcf207f2-4cf1-4774-a505-f3fc276a390f@w40g2000yqd.googlegroups.com>
NNTP-Posting-Host: netlab.cs.rpi.edu
Content-Type: text/plain; charset=ISO-8859-1
To: (Usenet)
Return-Path: <cppmods@ruralroute.cs.rpi.edu>
X-Original-Date: Sat, 18 Apr 2009 02:28:31 -0700 (PDT)
X-Submission-Address: std-c++@netlab.cs.rpi.edu
Xref: g2news2.google.com comp.std.c++:462

Hi!

Is anyone aware of whether the following code is supposed to compile?

   auto concept HasFoo<typename T> {
     void foo(T);
   }

   template<typename T>
     requires HasFoo<T>
   void foo(T const&) {}

   int main() {
     foo(42);
   }

It does compile using "conceptg++" (svn 727).  I'm not sure whether
this is really a good behaviour.  I came across this because I tried
to write a general function template that enables swapping lvalue with
rvalue without the need for any further specialized overloads:

   template<typename T>
     requires MoveConstructible<T> && MoveAssignable<T>
   void swap(T & a, T & b) { // <-- accepting lvalues only
     T temp ( move(a) );
     a = move(b);
     b = move(temp);
   }

   template<typename T, typename U>
     requires !SameType<T&&,U&&> // avoids ambiguity
           &&  HasSwap <T&, U&>  // for forwarding
   inline void swap(T && t, U && u)
   {
     swap(t,u); // forwarding to lvalue-swap
   }

I realized that in a rare combination of types T and U this could lead
to an infinite recursion via HasSwap<T&,U&>::swap.

I think this "recursive constraint" situation deserves some attention
and that it makes more sense to ignore the current function template
(that's being defined) as a function that satisfies any requirements
mentioned in its requires clauses. This would make the first example
ill-formed.


Cheers!
SG

-- 
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]



