Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost TraitsType Question
From: Rawate, Vishal CIV NAVAIR-WD-5-2-7-1-1-0-E., 527110E (vishal.rawate_at_[hidden])
Date: 2012-10-04 18:19:22


Yes Function overloading or Template specialization would work. Bu again all the functions have to perform the same tasks just the types are different.

For example I would like to do this.
Template<typename T>

 Void setTag(T myVariable)
 {
      If(T == short)
     {
                 myType = short;
     }

         If(T == long)
         {
                 myType = long;
         }

}

Thanks for all the help.

-----Original Message-----
From: boost-users-bounces_at_[hidden] [mailto:boost-users-bounces_at_[hidden]] On Behalf Of Jeremiah Willcock
Sent: Thursday, October 04, 2012 11:15
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] Boost TraitsType Question

On Thu, 4 Oct 2012, Rawate, Vishal CIV NAVAIR-WD-5-2-7-1-1-0-E., 527110E wrote:

> Hello,
>
> I am writing a function using templates in C++.I want to find the type of variable that is being to the function. I was wondering if I could use the Boost TypeTraits library or is there another library that I can use.
> I would highly appreciate any help.
>
> Thanking in advance.
>
> Vishal
>
>
> CodeSnipet:
>
> Template<typename T>
>
> Void setTag(T myVariable)
> {
> If(T == short)
> {
> Do something;
> }
>
> If(T == long)
> {
> Do something;
> }
>
> }

Wouldn't standard overloading (or function template complete
specialization) work just as well here?

template <typename T>
void setTag(T myVariable) { /* Base case */ }

void setTag(int myVariable) { /* int case */ }
void setTag(long myVariable) { /* long case */ }

-- Jeremiah Willcock
_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users




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