Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Specializing Perfect Forwarding Templates?

Reply
Thread Tools

Specializing Perfect Forwarding Templates?

 
 
itaj sherman
Guest
Posts: n/a
 
      03-16-2011
On Mar 16, 7:20 pm, Scott Meyers <(E-Mail Removed)> wrote:
> On 3/16/2011 9:47 AM, Noah Roberts wrote:
>
> > You can do what you're trying to do with a dispatching pattern:

>
> Simple testing suggests I can achieve the same end with less work and
> using an arguably clearer approach via enable_if. Overloading my
> forwarding template as follows works for me with VC10 and gcc 4.5 (on
> simple tests):
>
> template<typename T>
> typename std::enable_if<
> !std::is_pointer<
> typename std::remove_reference<T>::type
> >::value
> >::type

> fwd(T&& param)
> {
> std::cout << "General forwarding template => ";
> f(std::forward<T>(param));
>
> }
>
> template<typename T>
> typename std::enable_if<
> std::is_pointer<
> typename std::remove_reference<T>::type
> >::value
> >::type

> fwd(T&& param)
> {
> std::cout << "Pointer forwarding template => ";
> f(std::forward<T>(param));
>
> }
>
> Am I overlooking a drawback to this technique?
>


I think this is what others meant too, but in my words: the resolution
feature of c++ (both in functions and template class specializations)
applies a very useful partial order on the specializations (per type
hierarchies and the specializations of the template's parameters).
This scheme only works for exact partitions (equivalence relation
rather than a partial order). This is why in my other post I was
trying to "abuse" the template class specialization feature in order
to achieve a workaround.

itaj
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
strange compile problem regarding const-ref v.s. perfect forwarding huili80@gmail.com C++ 3 10-29-2012 09:11 PM
Perfect Forwarding in Runtime (rvalue reference) dervih C++ 3 07-13-2012 02:03 PM
using std::function, std::bind, perfect forwarding Andrew Tomazos C++ 1 12-23-2011 10:19 AM
Perfect Forwarding + static_assert [C++0x] Scott Meyers C++ 6 12-05-2010 08:21 PM
Perfect function forwarding Alexis Nikichine Javascript 6 12-28-2005 02:39 PM



Advertisments