Implementing Trivial Relocation in Library -- Barry Revzin
One of the reasons that I’m excited for Reflection in C++ is that it can permit you to implement, as a library, many things that previously required language features. In this post, I’m going to walk through implementing P2786R8 (“Trivial Relocatability For C++26”).
Implementing Trivial Relocation in Library
by Barry Revzin
From the article:
The goal here is not to say that the design is right or wrong (although the syntax certainly is suspect), but rather to show the kinds of things that reflection can solve.
We’ll just go straight to the wording and translate it into code as we go:
Trivially Relocatable Types
Scalar types, trivially relocatable class types (11.2 [class.prop]), arrays of such types, and cv-qualified versions of these types are collectively called trivially relocatable types.
This sure sounds like a type trait! Except in the world of reflection, those are just functions. How would we implement such a thing? We could start by doing this:
consteval auto is_trivially_relocatable(std::meta::info type)
-> bool
{
type = type_remove_cv(type);
return type_is_scalar(type)
or (type_is_array(type)
and is_trivially_relocatable(
type_remove_all_extents(type)
))
or is_trivially_relocatable_class_type(type);
}This is a fairly literal translation, where
is_trivially_relocatable_class_typeis something to be written shortly. But one interesting thing about thetype_remove_all_extentstype trait (i.e.std::remove_all_extents) is that it also works for non-array types, just returning back the same type.

How do you minimise locking between producers and consumers? Lucian Radu Teodorescu describes a common, but currently undocumented, design pattern. Design patterns can help us reason about code. They are like algorithms that are vaguely defined in the code. Once we recognise a pattern, we can easily draw conclusions about the behaviour of the code without looking at all the parts. Patterns also help us when designing software; they are known solutions to common problems.