Date: Mon, 3 Feb 2025 10:59:44 +0000
On Sun, Feb 2, 2025 at 9:21 PM Christof Meerwald wrote:
>
> That sounds more like a strong or opaque typedef, see
> https://open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0109r0.pdf
Here's the lines I was thinking along. Let's say we have a very simple
translation unit, something like:
class IndexSet;
extern void RemoveDuplicates(IndexSet&);
extern void SmoothenValues(IndexSet&);
void NormaliseIndexSet( IndexSet &arg )
{
RemoveDuplicates(arg);
SmoothenValues(arg);
}
The above translation unit will become an object file and it will
export the function "NormaliseIndexSet" mangled in such a way that it
accepts an "IndexSet". The compiler is able to do this because it
knows how to mangle "class IndexSet" irrespective of how complicated
the class definition is.
Here's an alternative:
#include <set>
typedef std::set<unsigned> IndexSet;
extern void RemoveDuplicates(IndexSet&);
extern void SmoothenValues(IndexSet&);
void NormaliseIndexSet( IndexSet &arg )
{
RemoveDuplicates(arg);
SmoothenValues(arg);
}
When compiling the above source file, the compiler emits a mangled
name for the function "NormaliseIndexSet". But in order to be able to
do this, the full definition of the template class "std::set" is
required inside the translation unit.
I was thinking an alternative would be something like:
typedef IndexSet <=> mangle("_Zt3setIjSt4lessIjESaIjEE");
extern void RemoveDuplicates(IndexSet&);
extern void SmoothenValues(IndexSet&);
void NormaliseIndexSet( IndexSet &arg )
{
RemoveDuplicates(arg);
SmoothenValues(arg);
}
But of course the above code isn't portable because the mangling is
different on different compilers.
But now I'm thinking that the "opaque typedef" would probably be a
better way of going about this -- so long as the opaque typedef can be
forward-declared without giving any info about the type.
>
> That sounds more like a strong or opaque typedef, see
> https://open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0109r0.pdf
Here's the lines I was thinking along. Let's say we have a very simple
translation unit, something like:
class IndexSet;
extern void RemoveDuplicates(IndexSet&);
extern void SmoothenValues(IndexSet&);
void NormaliseIndexSet( IndexSet &arg )
{
RemoveDuplicates(arg);
SmoothenValues(arg);
}
The above translation unit will become an object file and it will
export the function "NormaliseIndexSet" mangled in such a way that it
accepts an "IndexSet". The compiler is able to do this because it
knows how to mangle "class IndexSet" irrespective of how complicated
the class definition is.
Here's an alternative:
#include <set>
typedef std::set<unsigned> IndexSet;
extern void RemoveDuplicates(IndexSet&);
extern void SmoothenValues(IndexSet&);
void NormaliseIndexSet( IndexSet &arg )
{
RemoveDuplicates(arg);
SmoothenValues(arg);
}
When compiling the above source file, the compiler emits a mangled
name for the function "NormaliseIndexSet". But in order to be able to
do this, the full definition of the template class "std::set" is
required inside the translation unit.
I was thinking an alternative would be something like:
typedef IndexSet <=> mangle("_Zt3setIjSt4lessIjESaIjEE");
extern void RemoveDuplicates(IndexSet&);
extern void SmoothenValues(IndexSet&);
void NormaliseIndexSet( IndexSet &arg )
{
RemoveDuplicates(arg);
SmoothenValues(arg);
}
But of course the above code isn't portable because the mangling is
different on different compilers.
But now I'm thinking that the "opaque typedef" would probably be a
better way of going about this -- so long as the opaque typedef can be
forward-declared without giving any info about the type.
Received on 2025-02-03 10:59:52