Commit graph

5179 commits

Author SHA1 Message Date
681cfbfd8c TreeExplorer: add warning due to the moving builder operations
this was a design decision, but now I myself run into that obvious mistake;
thus not sure if this is a good design, or if we need a dedicated operation
to finish the builder and retrieve the iterable result.
2017-12-08 05:34:28 +01:00
ce1ee71955 TreeExplorer: clarify base initialisation
as it turned out, when "inheriting" ctors, C++14 removes the base classes' copy ctors.
C++17 will rectify that. Thus for now we need to define explicitly that
we'll accept the base for initialising the derived. But we need do so
only on one location, namely the most down in the chain.
2017-12-08 05:32:04 +01:00
aa008d6d4a TreeExplorer: draft my requirements for packaging a TreeExplorer pipeline as IterSource
Since this now requires to import iter-adapter-stl.hpp and iter-source.hpp
at the same time, I decided to drop the convenience imports of the STL adapters
into namespace lib. There is no reason to prefer the IterSource-based adapters
over the iter-adapter-stl.hpp variants of the same functionality.
Thus better always import them explicitly at usage site.


...actual implementation of the planned IterSource packaging is only stubbed.
But I needed to redeclare a lot of ctors, which doesn't seem logical
And I get a bad function invocation from another test case which worked correct beforehand.
2017-12-07 05:48:36 +01:00
9b9dcb2b78 TreeExplorer: add yet another convoluted example
Yay!
...and all of this works flawless right away
2017-12-07 03:11:11 +01:00
160a5e5465 TreeExplorer: cover further flavours of predicate definition 2017-12-07 02:19:19 +01:00
e9e7004a2e TreeExplorer: simple implementation based on eager pulling and an Invariant
lazy pulling would require us to store an additional bool
(the way the FilterIterator from itertools does)
2017-12-07 02:19:14 +01:00
2eacde7f2c TreeExplorer: draft the filter operation
should be low hanging fruit now....
2017-12-06 02:33:32 +01:00
085b304a38 TreeExplorer: finish test coverage of expand+transform 2017-12-06 02:02:22 +01:00
9e9c6c3ec6 TreeExplorer: solve refresh-problem when expanding children
We need a way for higher layers to discard their caching and re-evaluate,
once some expansion layer was invoked to replace the current element with
its (functionally defined) "children" -- otherwise the first child will
remain obscured by what was there beforehand.

Solution is to pass such manipulation calls through the full chain of
decorators, allowing them to refresh themselves when necessary. To achieve
that technially, we add a base layer to absorb any such call passed down
through the whole decorator chain -- since we can not assume that the
parent, the original source core implements those manipualation calls
like expandChildren()
2017-12-06 00:43:43 +01:00
b8cf274de6 Refactoring: extract new duck detectors
due to switching from ADL extension points to member functions,
we now need to detect a "state core" type in a different fashion.
The specific twist is that we can not spell out the full signature
in all cases, since the result type will be formed as a consequence
of this type detection. Thus there are now additional detectors to
probe for the presence of a specific function name only, and the
distinction between members and member functions has been sharpened.
2017-12-05 06:05:33 +01:00
52edf7d930 Refactoring: switch IterStateWrapper to member function based API
Considering the fact that we are bound to introduce yet another iteration control function,
because there is literally no other way to cause a refresh within the IterTreeExplorer-Layers,
it is indicated to reconsider the way how IterStateWrapper attaches to the
iteration control API.

As it turns out, we'll never need an ADL-free function here;
and it seems fully adequate to require all "state core" objects to expose
the API as argument less member function. Because these reflect precisely
the contract of a "state core", so why not have them as member functions.
And as a nice extra, the implementation becomes way more concise in
all the cases refactored with this changeset!

Yet still, we stick to the basic design, *not* relying on virtual functions.
So this is a typical example of a Type Class (or "Concept" in C++ terminology)
2017-12-05 03:28:00 +01:00
81c6136509 TreeExplorer: define interaction between expand and transform-operation
good news: it (almost) works out-of-the-box as expected.

There is only one problem: expandChildren() alters the content of the
data source, yet downstream decorators aren't aware of that fact and
continue to present cached evaluations, until the next iterate() call
is issued. Yet unfortunately this iterate already consumes the first
of the expanded children, which thus gets shadowed by the cached
outcome of parent node already consumed and expanded at that point

See the first example:

"10-8-expand-8-4-2-6-4-2"
should be 6 ^^^
2017-12-04 06:11:08 +01:00
823848db37 TreeExplorer: document arcane special case
...which happens to be supported out of the box,
due to the generic adaptor magic shared with the explore-operation

Exploiting this feature, some functor could even subvert the layering order
2017-12-04 04:34:27 +01:00
ca270028a9 TreeExplorer: transform-operation implemented and covered in test 2017-12-04 04:34:27 +01:00
b5453cc429 TreeExplorer: reimplementation with simpler design
- always layer the TreeExplorer (builder) on top of the stack
- always intersperse an IterableDecorator in between adjacent layers
- consequently...
  * each layer implementation is now a "state core"
  * and the source is now always a Lumiera Iterator

This greatly simplifies all the type rebindings and avoids the
ambiguities in argument converison. Basically now we can always convert
down, and we just need to pick the result type of the bound functor.

Downside is we have now always an adaptation wrapper in between,
but we can assume the compiler is able to optimise such inline
accessors away without overhead.
2017-12-04 04:34:26 +01:00
e58e4553f4 TreeExplorer: make the Core -> Core design work, kind of
...yet this seems like a rather bad idea,
it breeds various problems and requires arcane trickery to make it fly

==> abandon this design
==> always intersperse an IterableDecorator between each pair of Layers
2017-12-04 04:34:24 +01:00
94d5801712 Library: add move-support to ItemWrapper
...especially relevant in the context of TreeExplorer,
where the general understanding is that the "Data Source" (whatever it is)
will be piggy-backed into the pipeline builder, and this wrapping is
conceived as being essentially a no-op.

It is quite possible we'll even start using such pipeline builders
in concert with move-only types. Just consider a UI-navigator state
hooked up with a massive implementation internal pointer tree attached
to all of the major widgets in the UI. Nothing you want to copy in passing by.
2017-12-04 04:26:43 +01:00
1df77cc4ff Library: investigate and fix an insidious problem with move-forwarding (util::join / transformIter)
As it turned out, we had two bugs luring in the code base,
with the happy result of one cancelling out the adverse effects of the other

:-D

 - a mistake in the invocation of the Itertools (transform, filter,...)
   caused them to move and consume any input passed by forwarding, instead
   of consuming only the RValue references.
 - but util::join did an extraneous copy on its data source, meaning that
   in all relevant cases where a *copy* got passed into the Itertools,
   only that spurious temporary was consumed by Bug #1.

(Note that most usages of Itertools rely on RValues anyway, since the whole
point of Itertools is to write concise in-line transformation pipelines...)

*** Added additional testcode to prove util::stringify() behaves correct
    now in all cases.
2017-12-04 04:23:30 +01:00
63a49bccfd Library: define string conversion trait more precisely
It is pointless to include pointers....
A pointer to string is not "basically a string",
and char is handled explicitly anyway.
2017-12-04 03:53:36 +01:00
e379ad82c6 Library: typeof obsoleted by decltype
Replace the remaining usages of the GNU extension 'typeof()'
by the now-standard 'decltype()' operator
2017-12-04 03:53:36 +01:00
c65c5f812b Library: put the new type rebinding trait into general use
Obsoletes and replaces the ad-hoc written type rebindings from
iter-adapter and friends. The new scheme is more consistent and does
less magic, which necessitates an additional remove_pointer<IT> within
the iterator adaptors. Rationale is, "pointer" is treated now just as
a primitive type without additional magic or unwrapping, since it is
impossible to tell generically if the pointer or the pointee was
meant to be the "value"
2017-12-02 02:51:51 +01:00
847593f18b Investigation: resolve the mystery and fix the problem
Oh well.
This kept me busy a whole day long -- and someone less stubborn like myself
would probably supect a "compiler bug" or put the blame on the language C++

So to stress this point: the compiler behaved CORRECT

Just SFINAE is dangerous stuff: the metafunction I concieved yesterday requires
a complete type, yet, under rather specific circumstances, when instantiating
mutually dependent templates (in our case lib::diff::Record<GenNode> is a
recursive type), the distinction between "complete" and "incomplete"
becomes blurry, and depends on the processing order. Which gave the
misleading impression as if there was a side-effect where the presence
of one definition changes the meaning of another one used in the same
program. What happened in fact was just that the evaluation order was
changed, causing the metafunction to fail silently, thus picking
another specialisation.
2017-12-02 02:51:51 +01:00
2c53dc2e57 Investigation: failure to detect nested typedef
a metafunction to detect nested typedefs worked perfectly in the test setup,
but failed once included into application code.
2017-12-02 02:51:37 +01:00
b104508685 Library: extract type diagnostics test helpers 2017-12-01 03:51:54 +01:00
674201f5ea Library: finish new form of the type rebinding trait 2017-12-01 03:25:51 +01:00
1047f2f245 Library: decide on the overall shape of the type rebinding helper
- we do strip references
- we delegate to nested typedefs

Hoever, we do *not* treat const or pointers in any way special --
if the user want to strip or level these, he has to do so explicitly.
Initially it seemed like a good idea to do something clever here, but
on the long run, such "special treatment" is just good for surprises
2017-12-01 02:43:27 +01:00
dce09ebe0d Library: better use a dedicated detector metafunction
...and check for presence of *all three* standard type bindings

 - value_type
 - reference
 - pointer
2017-11-30 23:41:12 +01:00
6bb288bf20 Library: search for a way to rebind to nested definitions
...automatically whenever those are present.
Up to now, we hat that as base case, which limited usage to those cases
where we already know such nested definitions are actually present
2017-11-30 23:28:00 +01:00
d73b0b05b2 Library: attempt to get more explicit type diagnostics
...including the various reference and pointer adornments;
typeid() unfortunately strips those, so we'll have to add them manually
2017-11-30 23:23:54 +01:00
60301f7523 Library: need an augmented version of the iterator type rebinding helper
yet another quick-n-dirty hack turned into an useful everyday helper...

but at least I need it to be symmetric in and universally applyable
2017-11-30 21:02:36 +01:00
a3a64147c1 TreeExplorer: implementation draft for the transform-operation
attempt to re-use the same traits as much as possible

NOTE: new code not passing compiler yet, but refactored old code
      does, and still passes unit test
2017-11-30 03:52:32 +01:00
09a263431c TreeExplorer: note further functionality to supplement
- add a filter (should be low hanging fruit)
- wrap the result as IterSource
2017-11-28 03:53:38 +01:00
5b86b660ae TreeExplorer: draft functionality of transform-operation 2017-11-28 03:53:09 +01:00
884af619a1 Library: change IterStateWrapper to delayed start-of-evaluation
this is a subtle change which, given all interfaces were used in a logically
consistent way, should not cause any observable change to the yielded elements.
But it changes runtime behaviour, insofar now the evalutaion is initiated
lazily, when first requesting a result type. Prior to this change, the
constructor immediately issued a call to the yield() extension point,
which presumably has the side-effect of preparing the core and initiating
any embedded evaluation, in order to get at the first result; it might
even detect an empty state.

Given the fact that all access operations on the iterator front-end perform
an empty check (and possibly throw at that point), this call is redundant.
2017-11-27 05:56:03 +01:00
134821ca15 DOC: document some of the language limitations highlighted by this research 2017-11-27 05:39:47 +01:00
d8f7a22123 TreeExplorer: cover all the remaining cases supported for the expansion functor 2017-11-27 05:07:06 +01:00
86856390e1 TreeExplorer: cover expansion using a different result type
here using a lambda with side-effect and returning a reference to
a STL collection with the children, which is managed elsewhere.
2017-11-27 05:07:06 +01:00
77c3226948 TreeExplorer: identify yet another subtle type inference problem
surprising behaviour encountered while covering more cases

...obviously the return type of ExpandFunctor::operator()
was inferred as value, even while the invoked functor, from which
this type was deduced, clearly returns a reference.

Solution is simple not to rely on inference, moreover since we know
the exact type in the enclosing scope, thanks to the refactoring which
made this ExpandFunctor a nested class

NOTE:
as it turned out, this is not a compiler bug,
but works as defined by the language:
on return type inference, the detected type is decayed,
which usually helps to prevent returning a reference to a temporary
2017-11-27 05:02:57 +01:00
6667a51a61 TreeExplorer: cover another use case expand( Val -> iter<Val> )
...which uncovered an error in the test fixture
plus helped to spot the spurious copy when passing the argument to the expand functor

And my GDB crashed when loading the executable, YAY!
so we'll need to coment out some code from now on,
until we're able to switch to a more recent toolchain  (#1118)
2017-11-26 22:35:43 +01:00
89005dbeb7 TreeExplorer: fix spurious copy of iterator (argument) on functor invocation
...since our iterators *always* yield a reference to the exposed element,
we can *always* get that referency into the nested yield to obtain the value
2017-11-26 22:29:51 +01:00
9e96ea8323 TreeExplorer: documentation of technicalities 2017-11-25 03:56:44 +01:00
76a11b3730 TreeExplorer: rename and refactor for readability
...while this implementation works now, it is still very complex and intricate.
I am still doubtful this is a good approach, but well, we need to try that route....
2017-11-25 03:54:41 +01:00
bb948bff34 TreeExplorer: working solution to accept generic lambda
but possible only for the iterator -> iterator case

Since we can not "probe" a generic lambda, we get only one shot:
we can try to bind it into a std::function with the assumed signature
2017-11-25 02:16:21 +01:00
4098e2024d TreeExplorer: Sketch how it might be possible to accept generic lambdas
...based on the research from yesterday
2017-11-24 23:48:56 +01:00
3614085ff7 Library: improve the function-signature detector to work as guard with enable_if
This is a consequence of the experiments with generic lambdas.
Up to now, lib::meta::_Fun<F> failed with a compilation error
when passing the decltype of such a generic lambda.

The new behaviour is to pick the empty specialisation (std::false_type) in such cases,
allowing to guard explicit specialisations when no suitable functor type
is passed
2017-11-24 23:48:56 +01:00
8bdd9e7d66 Research: build "anything function-like" trait
...with the sole exception that such a trait can not detect
a templated or overloaded function call operator
2017-11-24 23:48:56 +01:00
2533565f83 Research: probing a generic lambda is not possible
...since all those metaprogramming techniques rely on SFINAE,
but *instantiating* a template means to compile it, which is more
than just substituate a type into the signature

If forming the signature fails -> SFINAE, try next one
If instantiating a template fails -> compile error, abort
2017-11-24 23:48:56 +01:00
01937f9736 Research: possiblity to detect a generic Lambda? 2017-11-24 23:48:56 +01:00
18553f22b2 TreeExplorer: cover both variants of functor signature by unit test (PASS) 2017-11-23 03:29:26 +01:00
c5311a116a TreeExplorer: concept how to generalise the expansion functor
Basically we want to support two distinct cases, just by slightly adapting
the invocation of the expansion functor:

Case-1: classical monadic flatMap:
        the Functor accepts a value yielded by the source iterator
        and builds a new "expaneded" iterator

Case-2: manipulation of opaque implementation state
        the Functor knows internal details of the source iterator
        and thus takes the source iterator as such as argument,
        performs some manipulation and then builds a new sub-iterator

A soulution to reconcile those two distinct cases can be built
with the help of a generic lambda
2017-11-23 03:06:02 +01:00