clean-up: ItemWrapper now stands on its own
...initially, this header was a collection of small helpers made on occasion; one of them, the `ItemWrapper` used in transforming pipelines came into widespread use and was much augmented and improved over the years. many other tiny helpers could be replaced by standard library facilities...
This commit is contained in:
parent
bc6a219543
commit
8960aed7ba
9 changed files with 46 additions and 58 deletions
|
|
@ -1,8 +1,8 @@
|
||||||
/*
|
/*
|
||||||
WRAPPER.hpp - some smart wrapping and reference managing helper templates
|
ITEM-WRAPPER.hpp - hold anything for unified handling
|
||||||
|
|
||||||
Copyright (C)
|
Copyright (C)
|
||||||
2009, Hermann Vosseler <Ichthyostega@web.de>
|
2009,2023 Hermann Vosseler <Ichthyostega@web.de>
|
||||||
|
|
||||||
**Lumiera** is free software; you can redistribute it and/or modify it
|
**Lumiera** is free software; you can redistribute it and/or modify it
|
||||||
under the terms of the GNU General Public License as published by the
|
under the terms of the GNU General Public License as published by the
|
||||||
|
|
@ -11,32 +11,34 @@
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** @file wrapper.hpp
|
/** @file item-wrapper.hpp
|
||||||
** Library implementation: smart-pointer variations, wrappers and managing holders.
|
** Adapter to store and hold an element of arbitrary type in local storage.
|
||||||
** This is (intended to become) a loose collection of the various small helper templates
|
** Notably, the difference between values and references can be levelled,
|
||||||
** for wrapping, containing, placing or handling a somewhat \em problematic other object.
|
** while default construction or copy abilities are passed through.
|
||||||
** Mostly these are implemented to suit a specific need and then factored out later on.
|
** Such an _inline container_ can be relevant for generic programming,
|
||||||
** - ReturnRef is similar to std::reference_wrapper, but with a function-like usage.
|
** especially to capture the result of an arbitrary function.
|
||||||
** - ItemWrapper is a similar concept, but used more like a smart-ptr. Notably,
|
** This container can be created empty (which requires to store an additional
|
||||||
** a value-object is stored inline, into an embedded buffer.
|
** state flag); the stored payload can be accessed through the dereferentiation
|
||||||
** Furthermore, ItemWrapper can be used to level differences between values,
|
** operator (similar to a smart-ptr or to std::optional). The interface was
|
||||||
** references and pointers, as it can be instantiated with any of them, offering
|
** shaped by its primary use case, which is to bind transforming functors
|
||||||
** (almost) uniform handling in all cases (useful for building templates)
|
** into a processing pipeline, or for caching the result of a computation.
|
||||||
** - FunctionResult is the combination of ItemWrapper with a functor object
|
** Another use case is to circumvent the finiteness of references, to
|
||||||
** to cache the function result value. It was split off into a separate
|
** re-bind them to another target, or to replace an immutable object.
|
||||||
** header \ref wrapper-function-result.hpp to reduce include impact
|
** @note the essential trait is that for each usage we have static,
|
||||||
** @remark most of this helper collection became obsolete with the evolution of the
|
** compile-time knowledge of the precise type with all its adornments,
|
||||||
** standard library — with the exception of ItermWrapper, which turned out to be
|
** while we can not assume _anything_ about this type when writing the
|
||||||
** very effective and is now pervasively used as part of transforming functor
|
** code, to allow for maximum flexibility of potential usages. Contrast
|
||||||
** pipelines, to cache the result of the transforming function invocation.
|
** this to the pattern of _type erasure_, where we discard specific
|
||||||
|
** knowledge after construction; for _such_ cases, opaque-holder.hpp
|
||||||
|
** might be a better fit.
|
||||||
** @see lib::TransformIter
|
** @see lib::TransformIter
|
||||||
** @see lib::explore
|
** @see lib::explore
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef LIB_WRAPPER_H
|
#ifndef LIB_ITEM_WRAPPER_H
|
||||||
#define LIB_WRAPPER_H
|
#define LIB_ITEM_WRAPPER_H
|
||||||
|
|
||||||
#include "lib/error.hpp"
|
#include "lib/error.hpp"
|
||||||
#include "lib/nocopy.hpp"
|
#include "lib/nocopy.hpp"
|
||||||
|
|
@ -55,32 +57,6 @@ namespace wrapper {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reference wrapper implemented as constant function,
|
|
||||||
* returning the (fixed) reference on invocation
|
|
||||||
*/
|
|
||||||
template<typename T>
|
|
||||||
class ReturnRef
|
|
||||||
{
|
|
||||||
T& ref_;
|
|
||||||
|
|
||||||
public:
|
|
||||||
ReturnRef(T& target) : ref_(target) { }
|
|
||||||
T& operator() () const { return ref_;}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
ReturnRef<T>
|
|
||||||
refFunction (T& target)
|
|
||||||
{
|
|
||||||
return ReturnRef<T> (target);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Universal value/ref wrapper accessible similar to a pointer.
|
* Universal value/ref wrapper accessible similar to a pointer.
|
||||||
* A copyable, assignable value object to hold a given value within
|
* A copyable, assignable value object to hold a given value within
|
||||||
|
|
@ -387,4 +363,4 @@ namespace wrapper {
|
||||||
|
|
||||||
|
|
||||||
}} // namespace lib::wrap
|
}} // namespace lib::wrap
|
||||||
#endif /*LIB_WRAPPER_H*/
|
#endif /*LIB_ITEM_WRAPPER_H*/
|
||||||
|
|
@ -103,7 +103,7 @@
|
||||||
#include "lib/meta/duck-detector.hpp"
|
#include "lib/meta/duck-detector.hpp"
|
||||||
#include "lib/meta/function.hpp"
|
#include "lib/meta/function.hpp"
|
||||||
#include "lib/meta/trait.hpp"
|
#include "lib/meta/trait.hpp"
|
||||||
#include "lib/wrapper.hpp"
|
#include "lib/item-wrapper.hpp"
|
||||||
#include "lib/iter-adapter.hpp"
|
#include "lib/iter-adapter.hpp"
|
||||||
#include "lib/iter-source.hpp" /////////////TICKET #493 : only using the IterSource base feature / interface here. Should really split the iter-source.hpp
|
#include "lib/iter-source.hpp" /////////////TICKET #493 : only using the IterSource base feature / interface here. Should really split the iter-source.hpp
|
||||||
#include "lib/iter-stack.hpp"
|
#include "lib/iter-stack.hpp"
|
||||||
|
|
|
||||||
|
|
@ -69,10 +69,10 @@
|
||||||
|
|
||||||
|
|
||||||
#include "lib/iter-adapter.hpp"
|
#include "lib/iter-adapter.hpp"
|
||||||
|
#include "lib/item-wrapper.hpp"
|
||||||
#include "lib/meta/value-type-binding.hpp"
|
#include "lib/meta/value-type-binding.hpp"
|
||||||
#include "lib/meta/function.hpp"
|
#include "lib/meta/function.hpp"
|
||||||
#include "lib/meta/trait.hpp"
|
#include "lib/meta/trait.hpp"
|
||||||
#include "lib/wrapper.hpp"
|
|
||||||
#include "lib/util.hpp"
|
#include "lib/util.hpp"
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@
|
||||||
#define LIB_RESULT_H
|
#define LIB_RESULT_H
|
||||||
|
|
||||||
#include "lib/error.hpp"
|
#include "lib/error.hpp"
|
||||||
#include "lib/wrapper.hpp"
|
#include "lib/item-wrapper.hpp"
|
||||||
#include "lib/meta/util.hpp"
|
#include "lib/meta/util.hpp"
|
||||||
#include "lib/null-value.hpp"
|
#include "lib/null-value.hpp"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
#ifndef LIB_WRAPPER_FUNCTION_RESULT_H
|
#ifndef LIB_WRAPPER_FUNCTION_RESULT_H
|
||||||
#define LIB_WRAPPER_FUNCTION_RESULT_H
|
#define LIB_WRAPPER_FUNCTION_RESULT_H
|
||||||
|
|
||||||
#include "lib/wrapper.hpp"
|
#include "lib/item-wrapper.hpp"
|
||||||
#include "lib/meta/function.hpp"
|
#include "lib/meta/function.hpp"
|
||||||
#include "lib/meta/function-closure.hpp"
|
#include "lib/meta/function-closure.hpp"
|
||||||
#include "lib/meta/util.hpp"
|
#include "lib/meta/util.hpp"
|
||||||
|
|
|
||||||
|
|
@ -34,8 +34,7 @@
|
||||||
#include "lib/meta/maybe-compare.hpp"
|
#include "lib/meta/maybe-compare.hpp"
|
||||||
#include "lib/meta/function-closure.hpp"
|
#include "lib/meta/function-closure.hpp"
|
||||||
#include "steam/control/command-signature.hpp"
|
#include "steam/control/command-signature.hpp"
|
||||||
//#include "lib/replaceable-item.hpp"
|
#include "lib/item-wrapper.hpp"
|
||||||
#include "lib/wrapper.hpp"
|
|
||||||
#include "lib/format-obj.hpp"
|
#include "lib/format-obj.hpp"
|
||||||
#include "lib/util.hpp"
|
#include "lib/util.hpp"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
#include "lib/random.hpp"
|
#include "lib/random.hpp"
|
||||||
#include "lib/util.hpp"
|
#include "lib/util.hpp"
|
||||||
|
|
||||||
#include "lib/wrapper.hpp"
|
#include "lib/item-wrapper.hpp"
|
||||||
#include "lib/wrapper-function-result.hpp"
|
#include "lib/wrapper-function-result.hpp"
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@
|
||||||
#include "lib/meta/variadic-rebind.hpp"
|
#include "lib/meta/variadic-rebind.hpp"
|
||||||
#include "lib/meta/typeseq-util.hpp"
|
#include "lib/meta/typeseq-util.hpp"
|
||||||
#include "lib/meta/function.hpp"
|
#include "lib/meta/function.hpp"
|
||||||
#include "lib/wrapper.hpp"
|
#include "lib/item-wrapper.hpp"
|
||||||
#include "lib/format-util.hpp"
|
#include "lib/format-util.hpp"
|
||||||
#include "lib/random.hpp"
|
#include "lib/random.hpp"
|
||||||
#include "lib/util.hpp"
|
#include "lib/util.hpp"
|
||||||
|
|
|
||||||
|
|
@ -163620,7 +163620,20 @@ Since then others have made contributions, see the log for the history.</font></
|
||||||
</node>
|
</node>
|
||||||
<node CREATED="1748622765812" ID="ID_1447472606" MODIFIED="1748622792373" TEXT="Header aufräumen">
|
<node CREATED="1748622765812" ID="ID_1447472606" MODIFIED="1748622792373" TEXT="Header aufräumen">
|
||||||
<node CREATED="1748622795210" ID="ID_971344498" MODIFIED="1748622815722" TEXT="wrapper.hpp ⟼ item-wrapper.hpp"/>
|
<node CREATED="1748622795210" ID="ID_971344498" MODIFIED="1748622815722" TEXT="wrapper.hpp ⟼ item-wrapper.hpp"/>
|
||||||
<node CREATED="1748622837148" ID="ID_1686776944" MODIFIED="1748622856501" TEXT="ReturnRef überflüssig machen"/>
|
<node COLOR="#5b280f" CREATED="1748622837148" ID="ID_1686776944" MODIFIED="1748642624085" TEXT="ReturnRef: bereits obsolet">
|
||||||
|
<richcontent TYPE="NOTE"><html>
|
||||||
|
<head>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>
|
||||||
|
...hat bereits keinerlei Verwendungen mehr (hab es wohl schrittweise durch std::ref() ersetzt ... ohne eigens darauf zu achten)
|
||||||
|
</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
</richcontent>
|
||||||
|
<icon BUILTIN="button_cancel"/>
|
||||||
|
</node>
|
||||||
<node CREATED="1748622823574" ID="ID_518076065" MODIFIED="1748622828698" TEXT="Kommentar glattziehen"/>
|
<node CREATED="1748622823574" ID="ID_518076065" MODIFIED="1748622828698" TEXT="Kommentar glattziehen"/>
|
||||||
</node>
|
</node>
|
||||||
</node>
|
</node>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue