Boost logo

Boost :

From: Roland Weiss (weissr_at_[hidden])
Date: 2004-12-13 05:51:57

Yuval Ronen wrote:
> I have to admit two things in shame:
> 1. My knowledge of the C++ standard is not that profound as to decide
> whether the "template" is necessary or not.
> 2. I also didn't quite understand your reply. What was the conclusion? Is
> the "template" needed to exist? Not needed to exist? Needed not to exist?
> So, in light of these shortcomings of mine, I decied to give it a try. I
> testes both versions (with and without the "template") on 3 compilers: GNU
> GCC 3.2, GNU GCC 3.4.2 and MSVC 7.1. The results were that GCC 3.2 and MSVC
> 7.1 accepted both versions, while GCC 3.4.2 accepted only the version
> without the "template".
> So what's the conlusion now?

They are not needed when /using/ any objects. Have a look at section 5.1 of

C++ Templates, The Complete Guide, Vandevoorde & Josuttis

for a quick overview on the topic when to use the keywords "typename"
and "template" to disambiguate template code. Short rule: never do this
outside of template code, and only for constructs depending on the
template parameters.


> Are these suggested get() methods still such a bad idea?
> Will they ever see the daylight?
>>>>But you can't. You have to write the following, as I showed
>>>> int a = some_any.template get<int>();
>>>?? There are no dependent types in that utterance. Unless some_any is
>>>not known to be a boost::any (?) Am I missing something?
>>I tried to track down the relevant section in the standard to
>>confirm what I wrote, but I couldn't. I was relying on C++PL,
>>3rd Ed, App C, section C.13.6, "Template as a Qualifier."
>>The example is (reduced):
>> struct Memory
>> {
>> template <typename T> T * get_new();
>> };
>> template <typename Allocator>
>> void
>> f(Allocator & m)
>> {
>> int * p1 = m.get_new<int>(); // error
>> int * p2 = m.template get_new<int>();
>> }
>>This Memory::get_new() is used within a function template, but
>>Stroustrup doesn't mention that it is precisely because get_new()
>>is dependent that "template" is needed, so I didn't think that it
>>was a dependent type.
>>Thinking further, I realized that m.get_new<int>() actually means
>>m.Allocator::get_new<int>(), so I now see that it is a dependent
>>type according to
>>In the OP's case, the invoked member function would be any<T>'s,
>>not T's, so it isn't dependent and "template" isn't needed, which
>>is what you implied.
>>Rob Stewart stewart_at_[hidden]
>>Software Engineer
>>Susquehanna International Group, LLP using std::disclaimer;
>>Unsubscribe & other changes:
> _______________________________________________
> Unsubscribe & other changes:

Boost list run by bdawes at, gregod at, cpdaniel at, john at