Boost logo

Boost Users :

Subject: Re: [Boost-users] [SmartPtr] shared_ptr as a default value in function template
From: Pekka Seppänen (pekka.seppanen_at_[hidden])
Date: 2013-05-23 09:57:58


On 23.5.2013 16:40, Igor R wrote:
>> It seems to be a MSVC related issue; Unless the templated function
>> (make_shared in this case) is in the same namespace as the called templated
>> function (f in this case) MSVC throws an error.
>
>
> Good finding, thanks!
>
> Note however that the following does compile in MSVC:
>
> #include <boost/shared_ptr.hpp>
> #include <boost/make_shared.hpp>
> void f(int, boost::shared_ptr<int> = boost::make_shared<int>())
> { }
> int main()
> {
> f(0);
> }
>
> So, it's still unclear in what cases exactly this bug occurs.

The bug occurs if both the default argument and the function that has the
default argument are templated. There could be some other cases too, but
either a) move everything under the same namespace scope, b) drop f()
template, c) drop default argument template (eg. non-templated make_shared
wrapper if the make_shared type does not relate to f()'s templated type T);
Every option sucks, just pick your poison.

So, template < typename T > void foo(T, arg_type arg = ns::templated<
some_type >()) does not work, but void foo (arg_type arg = ns::templated<
some_type >()) and template < typename T > void foo(T, arg_type arg =
ns::not_templated()) work.

Typical MSVC everyday bs...

-- Pekka


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