Is it possible to deduce whether type is incomplete without compilation failure?

后端 未结 2 538
借酒劲吻你
借酒劲吻你 2021-01-18 18:02

I want to achieve behavior like sizeof(complete_type) will return real sizeof, and sizeof(incomplete_type) - will be just 0

I need this to provide extended run time

2条回答
  •  情深已故
    2021-01-18 18:24

    Do not try to do that.

    It is fundamentally unsound. Templates are parametrized by types, not instantiation point. A class type is not complete or not in itself, it is complete at some point during translation.

    A template instantiated on some types must have the exact same semantic in every instantiation.

    If not, the behaviour is not defined.

提交回复
热议问题