Alias template slim
Header:
proxy.h
Module:proxy
Namespace:pro::inline v4::skills
Since: 4.0.0
template <class FB>
using slim = typename FB::template restrict_layout<sizeof(void*), alignof(void*)>;
The alias template slim
modifies a specialization of basic_facade_builder
by restricting memory layout to single-pointer-size.
Notes
Let F
be a built facade type.
- The contained pointer type of
proxy<F>
must itself fit into single-pointer-size.- Typical examples:
T*
,std::unique_ptr<T>
(empty deleter). - Counter-examples:
std::shared_ptr<T>
,std::unique_ptr<T, D>
with a stateful deleter.
- Typical examples:
- For best performance create
proxy<F>
objects via the library functions (make_proxy
,allocate_proxy
,make_proxy_shared
andallocate_proxy_shared
, etc.); they automatically honor the layout constraint. - A
proxy<F>
object itself also stores bookkeeping metadata; its size is implementation-defined and can exceed single-pointer-size.
Example
#include <memory>
#include <proxy/proxy.h>
struct Default : pro::facade_builder::build {};
struct Slim : pro::facade_builder //
::add_skill<pro::skills::slim> //
::build {};
int main() {
static_assert(sizeof(pro::proxy<Default>) > sizeof(pro::proxy<Slim>));
static_assert(pro::proxiable<int*, Default>);
static_assert(pro::proxiable<std::unique_ptr<int>, Default>);
static_assert(pro::proxiable<std::shared_ptr<int>, Default>);
static_assert(pro::proxiable<int*, Slim>);
static_assert(pro::proxiable<std::unique_ptr<int>, Slim>);
// std::shared_ptr is too large for a slim facade
static_assert(!pro::proxiable<std::shared_ptr<int>, Slim>);
// pro::make_proxy_shared works with a slim facade
pro::proxy<Slim> p = pro::make_proxy_shared<Slim>(123);
}