Boost logo

Boost Users :

From: Ian McCulloch (ianmcc_at_[hidden])
Date: 2005-03-19 11:37:50


Peter Dimov wrote:

> Peter Dimov wrote:
>> Ian McCulloch wrote:
>>> Peter Dimov wrote:
>>
>> [...]
>>
>>> I don't get it: can't you detect whether
>>> nested::result<nested(T)>::type exists? As long as the primary
>>> template of nested::result is defined as an empty struct this should
>>> work fine(?).
>>
>> No, consider what happens when 'nested' is int (*) (), for example.
>
> Hm, it can't be int (*) (), because result_of will not attempt to look for
> a nested result, but it can be an user-defined type with no nested result,
> or a member named result.

Wouldn't both those cases (no nested result, or a member named result) cause
a substitution failure?

#include <iostream>

struct foo
{
   template <typename T>
   struct result { typedef int type; };
};

struct bar
{
   template <typename T>
   struct result {};
};

struct baz
{
   void result() {}
};

struct bat
{
};

void func(...)
{
   std::cout << "func(...)\n";
}

template <typename T>
typename T::result<T(int)>::type
func(T const& x)
{
   std::cout << "func(T const&)\n";
   return typename T::result<T(int)>::type();
}

int main()
{
   func(foo());
   func(bar());
   func(baz());
   func(bat());
}

This compiles cleanly with g++ 3.3.4 and produces
func(T const&)
func(...)
func(...)
func(...)

Cheers,
Ian


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net