Mario
Mario

Reputation: 322

Adding const to function template pointer argument

Consider:

template<typename X>
inline typename std::enable_if< std::is_pointer<X>::value, void>::type
replyOk(X pointer)
{
    *pointer = *pointer; //for sake of example
} 

Is it possible to add constness to the pointed data so that *pointer = *pointer creates a compiler error.

For example I can do

...
replyOk(X const pointer)
...

But this adds constness to the variable pointer not what it points to. I'm not sure that even makes sense...

Upvotes: 2

Views: 265

Answers (1)

T.C.
T.C.

Reputation: 137310

I don't see the point of the enable_if.

template<typename X>
inline void replyOk(const X* pointer) {
  //...
}

Upvotes: 3

Related Questions