On Apr 7, 1:18 pm, "Victor Bazarov"
> Damian wrote:
> > On Apr 7, 10:10 am, Ron Natalie
> >> Damian wrote:
> >>> Hi there,
>
> >>> I would like to restrict a template parameter to a template
> >>> functioned to either a signed or unsigned type, but not both.
>
> >>> For example, the following templated function should ideally only be
> >>> instantiated with unsigned types.
>
> >>> template
> >>> inline T id(T *i) {
> >>> return i;
> >>> }
>
> >>> void foo() {
> >>> (void)id
> >>> (void)id
> >>> }
>
> >> I don't know what algorithm you are indending to implement (your
> >> example is contrived and invalid).
>
> > Err, I meant
>
> > template class
> > unsignedness restriction here?
> > inline T id(T i) {
> > return i;
> > }
>
> > It is contrived. I don't think it's important for you to see the
> > algorithm. I want to know how to restrict the signedness of templates
> > in the general case. I have found that when I post specifics about the
> > algorithm, people focus their comments on the algorithm, when I'm
> > interested in entirely something else.
>
> Often enough we see folks asking "how do I
> it would solve some problem they allegedly have, while the actual
> solution to what's holding them from an acceptable result is nothing
> close. That is why sometimes, especially if the solution isn't at
> all an easy one, we might need proof (to ourselves) that we're not
> spending time solving the problem that you don't actually have.
>
> There is nothing personal here, please understand.
Not taking anything personally. I understand list traffic frequently
deals with questions about algorithms. However, while I am sure many
of this groups' members are quite skilled in algorithms, it is not
typically what I would come to a C++ list for.
Really what I am interested in how to restrict template arguments on
signedness as well as base class. It looks like boost has some
sophisticated template tools so I will look into them more deeply.
Thanks for bringing them to my attention.
> As to your particular inquiry, you should probably look into Boost's
> "enable_if" template and type traits, so you could "enable if your
> type T has a trait of being of the unsigned [integral] variety".
Thanks. I will look into enable_if construct in Boost.
Damian