|
|
Up |
|
|
  |
Author: flopbucketflopbucket Date: May 14, 2008 11:27
Hi,
I want to provide a specialization of a class for any type T that is a
std::map.
template
class Foo
{
// ...
};
template
class Foo >
{
// ...
};
It seems to work - is this the correct way to do this?
Foo uses the normal template, but Foo > for any
types of T1 and T2 uses the specifalization?
Thanks
|
| |
|
| | 8 Comments |
|
  |
Author: Victor BazarovVictor Bazarov Date: May 14, 2008 12:01
flopbucket wrote:
> Hi,
>
> I want to provide a specialization of a class for any type T that is a
> std::map.
>
> template
> class Foo
> {
> // ...
> };
>
> template
> class Foo >
> {
> // ...
> };
>
> It seems to work - is this the correct way to do this?
|
| Show full article (0.67Kb) |
|
| | no comments |
|
  |
Author: flopbucketflopbucket Date: May 14, 2008 12:51
Hi,
First, thanks for the reply.
>> Foo uses the normal template, but Foo > for any
>> types of T1 and T2 uses the specifalization?
>
> Not sure what you're asking here.
What I was trying to say was that if I declare:
Foo myFoo();
The instantiation will be for the normal/not-specialized template.
But if I declare:
Foo > myFoo2();
it will use the specialization... and that regardless of the types
used for std::map (in this case, int and std::string), any
"Foo > myFooExample()" will always
instantiate the specialization.
Thanks
|
| |
| no comments |
|
  |
Author: Victor BazarovVictor Bazarov Date: May 14, 2008 13:06
flopbucket wrote:
> Hi,
>
> First, thanks for the reply.
>
>
>>> Foo uses the normal template, but Foo > for any
>>> types of T1 and T2 uses the specifalization?
>> Not sure what you're asking here.
>
> What I was trying to say was that if I declare:
>
> Foo myFoo();
>
> The instantiation will be for the normal/not-specialized template.
Yes. Of course, 'myFoo' in that case is a function, but the template
is still instantiated, I believe.
|
| Show full article (1.05Kb) |
| no comments |
|
  |
Author: Greg HerlihyGreg Herlihy Date: May 14, 2008 13:20
On May 14, 12:51Â pm, flopbucket hotmail.com> wrote:
> Hi,
>
> First, thanks for the reply.
>
>>> Foo uses the normal template, but Foo > for any
>>> types of T1 and T2 uses the specifalization?
>
>> Not sure what you're asking here.
>
> What I was trying to say was that if I declare:
>
> Foo myFoo();
I believe that you mean to declare an object (and not a function):
Foo myFoo;
> The instantiation will be for the normal/not-specialized template.
Yes.
|
| Show full article (1.23Kb) |
| no comments |
|
  |
Author: flopbucketflopbucket Date: May 14, 2008 13:26
>
> Yes. Of course, 'myFoo' in that case is a function, but the template
> is still instantiated, I believe.
Right, my mistake. Should bee 'Foo myFoo;'
>
> Yes. Or do you still have a doubt about that?
No, thanks, just wanted to run it by some experts - I've done
specializations before but this one was a bit more "advanced" then
normal basic types, since std::map<> itself is a template. I just
wasn't sure of myself.
Thanks for the clarifications.
|
| |
| no comments |
|
  |
Author: Victor BazarovVictor Bazarov Date: May 14, 2008 15:28
Greg Herlihy wrote:
> On May 14, 12:51 pm, flopbucket hotmail.com> wrote:
>> Hi,
>>
>> First, thanks for the reply.
>>
>>>> Foo uses the normal template, but Foo > for any
>>>> types of T1 and T2 uses the specifalization?
>>> Not sure what you're asking here.
>> What I was trying to say was that if I declare:
>>
>> Foo myFoo();
>
> I believe that you mean to declare an object (and not a function):
>
> Foo myFoo;
>
>> The instantiation will be for the normal/not-specialized template.
>
> Yes. ...
|
| Show full article (2.51Kb) |
| no comments |
|
  |
Author: James KanzeJames Kanze Date: May 15, 2008 01:32
On May 14, 10:20 pm, Greg Herlihy mac.com> wrote:
> On May 14, 12:51 pm, flopbucket hotmail.com> wrote:
>>>> Foo uses the normal template, but Foo
>>>>>> for any types of T1 and T2 uses the
>>>> specifalization?
>>> Not sure what you're asking here.
>> What I was trying to say was that if I declare:
>> Foo myFoo();
> I believe that you mean to declare an object (and not a function):
> Foo myFoo;
>> The instantiation will be for the normal/not-specialized template.
> Yes.
>> But if I declare:
>> Foo > myFoo2();
> Again, I believe that you want:
> Foo > myFoo2;
|
| Show full article (3.02Kb) |
| no comments |
|
  |
|
|
  |
Author: Greg HerlihyGreg Herlihy Date: May 15, 2008 04:19
On May 14, 3:28Â pm, Victor Bazarov comAcast.net> wrote:
> Greg Herlihy wrote:
>
>> The answer depends on how many template parameters "std::map"
>> requires. The usual number is two - the two specified by the C++
>> Standard. An implementation however is allowed to require additional
>> temmplate type parameters for a std::map. So, assuming that std::map
>> requires only two type parameters, then the answer is "yes".
>
> I don't think it has anything to do with the number of arguments the
> template takes/has. Â The specialisation is not a template with a
> template template argument (I believe that's what you're thinking of...)
>
> For instance,
>
> Â Â Â template class TwoArgs {};
> Â Â Â template struct Foo { enum {a=0}; };
> Â Â Â template struct Foo > { enum {a=1}; };
>
> Â Â Â int main() { ...
|
| Show full article (2.88Kb) |
| no comments |
|
RELATED THREADS |
  |
|
|
|
|
|