nim-lang / RFCs

A repository for your Nim proposals.
135 stars 26 forks source link

[C++] Member pragma #530

Closed jmgomez closed 10 months ago

jmgomez commented 12 months ago

Abstract

The member pragma would allow to attach a function to a type in the same way virtual does it today. Except it doesnt introduce the virtual word in the declaration.

Motivation

Allow users to define members such as regular functions, destructors or other operators.

Description

Syntax is the same as virtual and constructor:


proc salute(self: FooPtr) {.member.} =
  ...
proc destroyFoo(self: FooPtr){.member:"~Foo()".} = 
  ...

proc `==`(self, other: Foo): bool {.member:"operator==('2 const & #2) const -> '0"} = 
...

Code Examples

No response

Backwards Compatibility

No response