2

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...

1
  • what about static_assert ? (I not sure to understand what you are trying to achieve here) Commented Jul 6, 2017 at 17:11

1 Answer 1

3

I don't see the point of the enable_if.

template<typename X>
inline void replyOk(const X* pointer) {
  //...
}
Sign up to request clarification or add additional context in comments.

2 Comments

Not quite equivalent but, assuming the OP only really cares about object pointers, this is much better. KISS.
Indeed that work fine, but that tells me I'm missing some basic concept about how the type resolution with template works. If I remove the * it still works fine! But there is a difference. The typeid of X and pointer changes. Without the *, X is pointer, but with the * , X it is. I was not excepted that. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.