Imagine two smart pointer templates, smart_ptr and smart_ptr_with_abort.
smart_ptrsimply callsdeletewhen the final reference to the object it holds is releasedsmart_ptr_with_abortcalls a class methodAbort()before deleting the object.
My object object has an Abort() method that must be called before the object is deleted.
Using concepts I can make smart_ptr_with_abort fail to compile if it's being used with an object that doesn't have an Abort() method.
Is there a way to achieve the reverse situation, where smart_ptr<object> would fail to compile but smart_ptr_with_abort<object> would succeed?
With more pondering on the question, I have chosen to approach the question differently thanks to Elliott.
The OP starts out this way and I quote:
Forgive me for my approach but instead let’s imagine two
classes that can take an arbitrary type upon construction.[1]The constraint is that one
class Amust only take a type that has a methodAbort()while anotherclass Bwill only take a type that does not have the methodAbort(). Ifclass Ais specialized with a type that doesn’t have the member functionAbort(), the program fails to compile. And ifclass Btakes a type that has the member functionAbort(), the program also fails to compile.Without your code I will write one approach here for posterity.
That is by using ”A Logical Negation expression”. We can simply negate the other
conceptto produce a newconcept.More on Logical negation expression:
[1] This approach shields us from having our design criticized. I admit I did that in my first answer and any critic would do the same I believe.
[2] That will be
class Ain our illustration.[3] That will be
class Bin our illustration.