Date: Fri, 13 Feb 2026 11:44:05 +0100
On 13/02/2026 10:14, Simon Schröder via Std-Proposals wrote:
>
> On Thu, Feb 12, 2026 at 2:08 PM David Brown via Std-Proposals
> <std-proposals_at_[hidden] <mailto:std-proposals_at_[hidden]>>
> wrote:
>
>
>
>
> An alternative solution would be if there were support in C++ for truly
> zero-overhead tag types. A "tag type" is a class type that contains no
> data, generally has no methods, and is used primarily for
> distinguishing
> overloads. My "tagged" functions could be handled making a tag type
> such as "irq_disabled" with a non-public constructor - you only get to
> create one with the type's friend "disable_interrupts()" function.
> Functions that should only be called with the interrupts disabled, will
> then take an "irq_disabled" parameter.
>
> Probably not the most elegant solution, but providing the tag as
> template parameter would have zero runtime-overhead.
>
Yes, I have thought a lot about that.
But what is missing there is that there is no way to control the use of
a type.
If we have a type "irq_disabled" with no public destructor, then the
only way I can get a member of that type and pass it on to a restricted
function is :
irq_disabled irqs_off = disable_interrupts();
modify_interrupt_table(irqs_off, new_interrupt_vector);
With a template, you can write :
using irqs_off = irq_disabled;
modify_interrupt_table<irqs_off>(new_interrupt_vector);
At no point are you forced to remember to call "disable_interrupts()".
You might as well just encode the requirement in the function name
(which is a well-established technique, but I hope to do better) :
modify_interrupt_table_with_irqs_off(new_interrupt_vector);
Even with non-type template parameters rather than type parameters, you
can't (AFAICS) enforce the correct usage here.
>
> On Thu, Feb 12, 2026 at 2:08 PM David Brown via Std-Proposals
> <std-proposals_at_[hidden] <mailto:std-proposals_at_[hidden]>>
> wrote:
>
>
>
>
> An alternative solution would be if there were support in C++ for truly
> zero-overhead tag types. A "tag type" is a class type that contains no
> data, generally has no methods, and is used primarily for
> distinguishing
> overloads. My "tagged" functions could be handled making a tag type
> such as "irq_disabled" with a non-public constructor - you only get to
> create one with the type's friend "disable_interrupts()" function.
> Functions that should only be called with the interrupts disabled, will
> then take an "irq_disabled" parameter.
>
> Probably not the most elegant solution, but providing the tag as
> template parameter would have zero runtime-overhead.
>
Yes, I have thought a lot about that.
But what is missing there is that there is no way to control the use of
a type.
If we have a type "irq_disabled" with no public destructor, then the
only way I can get a member of that type and pass it on to a restricted
function is :
irq_disabled irqs_off = disable_interrupts();
modify_interrupt_table(irqs_off, new_interrupt_vector);
With a template, you can write :
using irqs_off = irq_disabled;
modify_interrupt_table<irqs_off>(new_interrupt_vector);
At no point are you forced to remember to call "disable_interrupts()".
You might as well just encode the requirement in the function name
(which is a well-established technique, but I hope to do better) :
modify_interrupt_table_with_irqs_off(new_interrupt_vector);
Even with non-type template parameters rather than type parameters, you
can't (AFAICS) enforce the correct usage here.
Received on 2026-02-13 10:44:11
