Topic: Variadic templates in C++0x


Author: Douglas Gregor <doug.gregor@gmail.com>
Date: Mon, 5 Jan 2009 02:23:06 CST
Raw View
On Dec 18 2008, 1:05 pm, Olivier <olivier.gr...@gmail.com> wrote:
> To summarise my previous post, my question was regarding the use of
> several variadic template parameters when not relying on template
> parameter deduction which to me would be a great addition to the
> language :
>
> -------------------------------------------
> template< typename Func0, typename Func1 >
>   class composition;
>
> template< typename Ret0, typename ... Args0, typename Ret1,
> typename ... Args1 >
>   class composition<Ret0 ( Args0 ... ), Ret1 ( Args1 ... )>
>   {
>   public:
>      typedef Ret0 (*Func0Type)( Args0 ... );
>      typedef Ret1 (*Func1Type)( Args1 ... );
>
>      composition( Func0Type func0, Func1Type func1 )
>         : func0_(func0), func1_(func1)
>      { }
>
>      void operator()( Args0 && ... args0, Args1 && ... args1 )

For others' benefit: this is the part that is currently ill-formed
according to the working paper, because a function parameter list is
not permitted to contain any function parameter packs not occurring at
the end of the parameter list.

> I'll be eager to get your feedback on this.

I agree with you; this code should be well-formed, especially because
the current behavior with respect to function parameter packs differs
from the behavior of template parameter packs. I've made the committee
aware of this issue through the U.S. national body comments on the
first Candidate Draft for C++0x, and I expect that this restriction
will be lifted before C++0x is finalized.

 - Doug


--
[ 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                      ]





Author: Olivier <olivier.grant@gmail.com>
Date: Wed, 7 Jan 2009 10:21:11 CST
Raw View
> I agree with you; this code should be well-formed, especially because
> the current behavior with respect to function parameter packs differs
> from the behavior of template parameter packs. I've made the committee
> aware of this issue through the U.S. national body comments on the
> first Candidate Draft for C++0x, and I expect that this restriction
> will be lifted before C++0x is finalized.

Great, thanks for the info Doug.

I know you are behind the project ConceptGCC (http://www.generic-
programming.org/software/ConceptGCC/) and was wondering if you would
add this feature to one of your upcoming releases or are you sticking
to the current C++0x standard draft ? I know you're a busy man but it
would be really interesting to have this implemented to start writing
some code taking advantage of this.

Thanks,

Olivier

--
[ 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                      ]





Author: Olivier <olivier.grant@gmail.com>
Date: Thu, 18 Dec 2008 15:05:05 CST
Raw View
Hi All,

I posted a message a few months back regarding variadic templates in
the upcomming C++0x revision. At the time, the comp.std.c++ discussion
group was down, despite the fact that this would have been the best
group to discuss it in. I'm only reposting now because the discussion
group is now alive again (thxs to moderators) and especially from lack
of time.

There is the link to the original post:
http://groups.google.com/group/comp.lang.c++.moderated/browse_thread/thread/240bc8b5d19c048/6a22241276c126c0?hl=en#6a22241276c126c0

To summarise my previous post, my question was regarding the use of
several variadic template parameters when not relying on template
parameter deduction which to me would be a great addition to the
language :

-------------------------------------------
template< typename Func0, typename Func1 >
  class composition;

template< typename Ret0, typename ... Args0, typename Ret1,
typename ... Args1 >
  class composition<Ret0 ( Args0 ... ), Ret1 ( Args1 ... )>
  {
  public:
     typedef Ret0 (*Func0Type)( Args0 ... );
     typedef Ret1 (*Func1Type)( Args1 ... );

     composition( Func0Type func0, Func1Type func1 )
        : func0_(func0), func1_(func1)
     { }

     void operator()( Args0 && ... args0, Args1 && ... args1 )
     {
           (*func0_)(std::forward<Args0>(args0) ...);
           (*func1_)(std::forward<Args1>(args1) ...);
     }

  private:
     Func0Type func0_;
     Func1Type func1_;
  };

template< typename Func0, typename Func1 >
  inline
  composition <Func0, Func1> make_composition( Func0 func0, Func1
func1 )
  {
     return composition<Func0, Func1>(func0, func1);
  }

int main( )
{
  void function0( int, int );
  void function1( char, double );

  make_composition(func0, func1)(1, 2, 'c', 3.0);

  return 0;
}
-------------------------------------------

I'll be eager to get your feedback on this.

Thanks,

Olivier Grant

--
[ 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                      ]