Date: Wed, 26 Nov 2025 00:04:30 +0000
On Tue, Nov 25, 2025 at 5:32 PM Oliver Hunt wrote:
>
> Another strategy to do what? You have yet to say.
The original paper I shared, as well as the link to Arthur's blog,
shows what the aim is. Here's that original post again:
https://lists.isocpp.org/std-proposals/2025/11/15942.php
In particular I recommend reading Arthur's blog post:
https://quuxplusone.github.io/blog/2022/12/01/chimeric-ptr/
> The different “implementation strategies” should be part of your proposal.
You're right. I intend to put a paper together showing not only the
proposed feature (i.e. std::chimeric_ptr), but also a few
alternatives.
> After the feature summary, the use cases, and the specification.
That too, yeah.
> Again, I do not know why you seem unwilling to do the bare minimum
> amount of work in a proposal, but until you actually do that you are simply
> wasting the time of every person who is trying to follow this list.
I'm giving people the chance to interject with ideas at an early stage.
In my last email, I shared a GodBolt for the Itanium ABI x86_64 which
was specific to the classes Colorful and Text, and it needed my
customised compiler. Just now I've taken that code and made it
generic, and also it works with unaltered GNU g++ trunk:
https://godbolt.org/z/zKh9fcrKG
And here is the entire GodBolt copy-pasted:
#include <cstdint> // intptr_t
#include <cstdio> // puts
#include <iostream> // cout, endl
using std::puts;
struct Widget {
virtual ~Widget(void) noexcept = default;
};
struct Text : virtual Widget {
int n;
Text(int const arg) : n(arg) {}
virtual void set_text(void) noexcept = 0;
};
struct Colorful : virtual Widget {
virtual void set_color(void) noexcept = 0;
};
struct Placard : Colorful, Text {
Placard(void) : Text(666) {}
void set_color(void) noexcept override { puts("Placard SetColor"); }
void set_text (void) noexcept override { puts("Placard SetText" ); }
};
struct Billboard : Text, Colorful {
Billboard(void) : Text(666) {}
void set_color(void) noexcept override { puts("Billboard SetColor"); }
void set_text (void) noexcept override { puts("Billboard SetText" ); }
};
// ================= The trickery begins below this line
template<class... Ts>
class MakeBeliever final {
MakeBeliever(MakeBeliever const& ) = delete;
MakeBeliever(MakeBeliever &&) = delete;
MakeBeliever &operator=(MakeBeliever const& ) = delete;
MakeBeliever &operator=(MakeBeliever &&) = delete;
std::intptr_t vtable[ 5u + sizeof...(Ts) ]{}; // all zero
std::intptr_t const *object = nullptr;
public:
template<class T>
constexpr MakeBeliever(T &&arg) noexcept
{
std::intptr_t *const vptr = vtable + sizeof vtable / sizeof *vtable;
int i = 0;
auto mylambda = [this,vptr,&arg,&i]<typename B>(void) -> void
{
// In the vtable, set the virtual base's offset
intptr_t &offset = vptr[ - 6 - i++ ];
auto *const pb = std::addressof( static_cast<B&>(arg) );
offset = (char*)pb - (char*)&this->object;
};
( mylambda.template operator()<Ts>(), ... );
// Set the vptr inside the make-believe object
object = vptr;
}
struct NewDerivedClass : virtual Ts... {};
constexpr NewDerivedClass *operator->(void) noexcept
{
return static_cast<NewDerivedClass*>(static_cast<void*>(&object));
}
};
void set_text_and_color( MakeBeliever<Colorful, Text> ct )
{
ct->set_text ();
ct->set_color();
}
int main(void)
{
Placard placard;
set_text_and_color( placard );
}
>
> Another strategy to do what? You have yet to say.
The original paper I shared, as well as the link to Arthur's blog,
shows what the aim is. Here's that original post again:
https://lists.isocpp.org/std-proposals/2025/11/15942.php
In particular I recommend reading Arthur's blog post:
https://quuxplusone.github.io/blog/2022/12/01/chimeric-ptr/
> The different “implementation strategies” should be part of your proposal.
You're right. I intend to put a paper together showing not only the
proposed feature (i.e. std::chimeric_ptr), but also a few
alternatives.
> After the feature summary, the use cases, and the specification.
That too, yeah.
> Again, I do not know why you seem unwilling to do the bare minimum
> amount of work in a proposal, but until you actually do that you are simply
> wasting the time of every person who is trying to follow this list.
I'm giving people the chance to interject with ideas at an early stage.
In my last email, I shared a GodBolt for the Itanium ABI x86_64 which
was specific to the classes Colorful and Text, and it needed my
customised compiler. Just now I've taken that code and made it
generic, and also it works with unaltered GNU g++ trunk:
https://godbolt.org/z/zKh9fcrKG
And here is the entire GodBolt copy-pasted:
#include <cstdint> // intptr_t
#include <cstdio> // puts
#include <iostream> // cout, endl
using std::puts;
struct Widget {
virtual ~Widget(void) noexcept = default;
};
struct Text : virtual Widget {
int n;
Text(int const arg) : n(arg) {}
virtual void set_text(void) noexcept = 0;
};
struct Colorful : virtual Widget {
virtual void set_color(void) noexcept = 0;
};
struct Placard : Colorful, Text {
Placard(void) : Text(666) {}
void set_color(void) noexcept override { puts("Placard SetColor"); }
void set_text (void) noexcept override { puts("Placard SetText" ); }
};
struct Billboard : Text, Colorful {
Billboard(void) : Text(666) {}
void set_color(void) noexcept override { puts("Billboard SetColor"); }
void set_text (void) noexcept override { puts("Billboard SetText" ); }
};
// ================= The trickery begins below this line
template<class... Ts>
class MakeBeliever final {
MakeBeliever(MakeBeliever const& ) = delete;
MakeBeliever(MakeBeliever &&) = delete;
MakeBeliever &operator=(MakeBeliever const& ) = delete;
MakeBeliever &operator=(MakeBeliever &&) = delete;
std::intptr_t vtable[ 5u + sizeof...(Ts) ]{}; // all zero
std::intptr_t const *object = nullptr;
public:
template<class T>
constexpr MakeBeliever(T &&arg) noexcept
{
std::intptr_t *const vptr = vtable + sizeof vtable / sizeof *vtable;
int i = 0;
auto mylambda = [this,vptr,&arg,&i]<typename B>(void) -> void
{
// In the vtable, set the virtual base's offset
intptr_t &offset = vptr[ - 6 - i++ ];
auto *const pb = std::addressof( static_cast<B&>(arg) );
offset = (char*)pb - (char*)&this->object;
};
( mylambda.template operator()<Ts>(), ... );
// Set the vptr inside the make-believe object
object = vptr;
}
struct NewDerivedClass : virtual Ts... {};
constexpr NewDerivedClass *operator->(void) noexcept
{
return static_cast<NewDerivedClass*>(static_cast<void*>(&object));
}
};
void set_text_and_color( MakeBeliever<Colorful, Text> ct )
{
ct->set_text ();
ct->set_color();
}
int main(void)
{
Placard placard;
set_text_and_color( placard );
}
Received on 2025-11-26 00:04:34
