Assuming two declarations:
const type x; // case a
type y; // case b
is it possible to detect case "a" or "b" in type
's constructor so that I can execute different operations?
From the standard §12.1/3 we have that:
A constructor can be invoked for a const, volatile or const volatile object. const and volatile semantics (7.1.6.1) are not applied on an object under construction. They come into effect when the constructor for the most derived object (1.8) ends.
therefore this
behaves like expected by never being const
-qualified at construction (otherwise how could you edit member objects in the body?). So, it seems it's not possible to use type traits on this
.
A use case for this would be the following: assuming you are working with an underlying C API that describe specific objects (in a much wider sense), taking hints on their future use along the lines of:
STATIC
= will not be modifiedDYNAMIC
= can be modified
one could create a wrapper around those C objects and give a STATIC
hint on a const
construction, and a DYNAMIC
hint on a non const construction. Of course const_cast
exists and could mess things up, but I'm assuming sane coding here :P.
Am I missing something (considering also C++11 and C++14)?