meta: introduce meta_ctx_arg[_t]
This commit is contained in:
@@ -32,6 +32,12 @@ struct meta_context {
|
||||
* @endcond
|
||||
*/
|
||||
|
||||
/*! @brief Disambiguation tag for constructors and the like. */
|
||||
class meta_ctx_arg_t final {};
|
||||
|
||||
/*! @brief Constant of type meta_context_arg_t used to disambiguate calls. */
|
||||
inline constexpr meta_ctx_arg_t meta_ctx_arg{};
|
||||
|
||||
/*! @brief Opaque meta context type. */
|
||||
class meta_ctx: private internal::meta_context {
|
||||
/*! @brief Attorney idiom like model to access the base class. */
|
||||
|
||||
@@ -196,13 +196,13 @@ class meta_any {
|
||||
public:
|
||||
/*! Default constructor. */
|
||||
meta_any() noexcept
|
||||
: meta_any{locator<meta_ctx>::value_or()} {}
|
||||
: meta_any{meta_ctx_arg, locator<meta_ctx>::value_or()} {}
|
||||
|
||||
/**
|
||||
* @brief Context aware constructor.
|
||||
* @param area The context from which to search for meta types.
|
||||
*/
|
||||
meta_any(const meta_ctx &area) noexcept
|
||||
meta_any(meta_ctx_arg_t, const meta_ctx &area) noexcept
|
||||
: storage{},
|
||||
ctx{&area},
|
||||
node{},
|
||||
@@ -226,7 +226,7 @@ public:
|
||||
* @tparam Type Type of object to use to initialize the wrapper.
|
||||
* @param value An instance of an object to use to initialize the wrapper.
|
||||
*/
|
||||
template<typename Type, typename = std::enable_if_t<!std::is_same_v<std::decay_t<Type>, meta_any> && !std::is_same_v<std::decay_t<Type>, meta_ctx>>>
|
||||
template<typename Type, typename = std::enable_if_t<!std::is_same_v<std::decay_t<Type>, meta_any>>>
|
||||
meta_any(Type &&value)
|
||||
: meta_any{std::in_place_type<std::decay_t<Type>>, std::forward<Type>(value)} {}
|
||||
|
||||
@@ -586,7 +586,7 @@ meta_any make_meta(Args &&...args) {
|
||||
template<typename Type>
|
||||
meta_any forward_as_meta(const meta_ctx &ctx, Type &&value) {
|
||||
// TODO it would be great if we had value and context construction support for meta_any
|
||||
meta_any elem{ctx};
|
||||
meta_any elem{meta_ctx_arg, ctx};
|
||||
elem.emplace<Type &&>(std::forward<Type>(value));
|
||||
return elem;
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ void meta_default_constructor([[maybe_unused]] meta_type_node &node) {
|
||||
if constexpr(std::is_default_constructible_v<Type>) {
|
||||
node.default_constructor = +[](const meta_ctx &ctx) {
|
||||
// TODO it would be great if we had value and context construction support for meta_any
|
||||
meta_any elem{ctx};
|
||||
meta_any elem{meta_ctx_arg, ctx};
|
||||
elem.emplace<Type>();
|
||||
return elem;
|
||||
};
|
||||
@@ -199,7 +199,7 @@ void meta_from_void([[maybe_unused]] meta_type_node &node) {
|
||||
if constexpr(!std::is_same_v<Type, void> && !std::is_function_v<Type>) {
|
||||
node.from_void = +[](const meta_ctx &ctx, void *element, const void *as_const) {
|
||||
// TODO it would be great if we had value and context construction support for meta_any
|
||||
meta_any elem{ctx};
|
||||
meta_any elem{meta_ctx_arg, ctx};
|
||||
element ? elem.emplace<std::decay_t<Type> &>(*static_cast<std::decay_t<Type> *>(element)) : elem.emplace<const std::decay_t<Type> &>(*static_cast<const std::decay_t<Type> *>(as_const));
|
||||
return elem;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user