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.
This commit is contained in:
Fischlurch 2017-12-08 04:58:18 +01:00
parent aa008d6d4a
commit ce1ee71955
4 changed files with 144 additions and 25 deletions

View file

@ -143,14 +143,7 @@ namespace lib {
: IterAdapter<Pos, DataHandle>
{
using _I = IterAdapter<Pos, DataHandle>;
using _I::IterAdapter;
iterator() =default; /////////////////////////////////////TICKET #1117 : why the hell do we need to declare all those ctor variants explicitly? I was under the impression ctor calls worked correct up to now without all this...
iterator(iterator&&) =default;
iterator(iterator const&) =default;
iterator(iterator& r) : iterator((iterator const&)r) { }
iterator& operator= (iterator &&) =default;
iterator& operator= (iterator const&) =default;
operator string() const {return _I::source()? string(*_I::source()) : ""; }
};

View file

@ -447,16 +447,17 @@ namespace lib {
* call, where some "expansion layer" consumes the current element and replaces it by an expanded
* series of new elements. Other layers might need to sync to this operation, and thus it is passed
* down the chain. For that reason, we need a dedicated BaseAdapter to adsorb such chained calls.
* @remark when building the TreeExplorer, the to-be-wrapped source is fed down into its place
* within BaseAdapter. For that reason, we need to lift the copy ctors of the base.
* Just inheriting the base class ctors won't do that, at least not in C++14.
*/
template<class SRC>
struct BaseAdapter
: SRC
{
using SRC::SRC;
BaseAdapter(SRC const& src) : SRC(src) { } ////////////////////////TODO why the hell do we need to redeclare all those ctor variants????
BaseAdapter(SRC && src) : SRC(src) { }
BaseAdapter(SRC & src) : SRC(src) { }
BaseAdapter() = default;
BaseAdapter(SRC const& src) : SRC(src) { }
BaseAdapter(SRC && src) : SRC(src) { }
void expandChildren() { }
};
@ -781,10 +782,6 @@ namespace lib {
/** pass-through ctor */
using SRC::SRC;
TreeExplorer(SRC const& src) : SRC(src) { } ////////////////////////TODO why the hell do we need to redeclare all those ctor variants???? why isn't copy initialisation propagated from the base ctors?
TreeExplorer(SRC && src) : SRC(src) { }
TreeExplorer(SRC & src) : SRC(src) { }
TreeExplorer() = default;

View file

@ -751,7 +751,7 @@ namespace test{
exploreIter = treeExplore(sequence)
.filter([](int i){ return i>30; })
.expand([](int i){ return CountDown{i-10, 20}; })
.expand([](uint i){ return CountDown{i-10, 20}; })
.transform([](uint u) -> char { return '@'+u-20; })
.asIterSource();

View file

@ -6035,18 +6035,147 @@
<icon BUILTIN="help"/>
</node>
</node>
<node BACKGROUND_COLOR="#fdfdcf" COLOR="#ff0000" CREATED="1512621185490" ID="ID_1611878074" MODIFIED="1512621201039" TEXT="Probleme">
<icon BUILTIN="messagebox_warning"/>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1512621202688" ID="ID_57740660" MODIFIED="1512621221197" TEXT="durchreichen der Basis-Konstruktoren">
<icon BUILTIN="flag-yellow"/>
<node COLOR="#338800" CREATED="1512621185490" ID="ID_1611878074" MODIFIED="1512706124361" TEXT="Probleme">
<icon BUILTIN="button_ok"/>
<node CREATED="1512621202688" ID="ID_57740660" MODIFIED="1512706113620" TEXT="durchreichen der Basis-Konstruktoren">
<icon BUILTIN="info"/>
<node CREATED="1512706139167" ID="ID_1731306892" MODIFIED="1512706156440" TEXT="Basis-Copy-Konstruktoren werden nicht geerbt">
<node CREATED="1512706158004" ID="ID_958479010" MODIFIED="1512706289090" TEXT="nicht in C++14">
<richcontent TYPE="NOTE"><html>
<head>
</head>
<body>
<p>
...da gibt es eine explizite Ausnahme-Regel.
</p>
<p>
Die Copy-Konstruktoren werden aus der Kandidaten-Menge entfernt.
</p>
<p>
</p>
<p>
Grund ist, da&#223; die default-Initialisierung der Member-Felder noch nicht hinrechend gekl&#228;rt war.
</p>
<p>
C++17 holt das nach
</p>
</body>
</html>
</richcontent>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1512621222901" ID="ID_701320194" MODIFIED="1512621233228" TEXT="bad function call">
<icon BUILTIN="flag-yellow"/>
<node CREATED="1512706162921" ID="ID_601609235" MODIFIED="1512706394332" TEXT="ab C++17 ist das anders">
<richcontent TYPE="NOTE"><html>
<head>
</head>
<body>
<p>
...dort wird einfach on-demand in der Basisklasse nachgeschaut.
</p>
<p>
Wenn dabei ein Basis-Copy-Ctor gezogen wird, dann wird eben default-Init f&#252;r die Felder im abgeleiteten Objekt gemacht.
</p>
<p>
Es gibt dann eine neue, explizite Regel, die verhindert, da&#223; zuf&#228;llig ein aus der Basis geerbter Ctor
</p>
<p>
die Signatur eines Copy-ctors &#252;berdeckt
</p>
</body>
</html>
</richcontent>
</node>
</node>
<node CREATED="1512706405155" ID="ID_1013782130" MODIFIED="1512706515474">
<richcontent TYPE="NODE"><html>
<head>
</head>
<body>
<p>
Allerdings gen&#252;gt es, dies an <i>einer</i>&#160;Stelle in der Kette zu erg&#228;nzen
</p>
</body>
</html>
</richcontent>
<richcontent TYPE="NOTE"><html>
<head>
</head>
<body>
<p>
...und zwar genau dort, wo erstmals ein Basis-Objekt akzeptiert wird.
</p>
<p>
Das ist bei uns im BaseAdapter, also der ersten Ebene &#252;ber dem zu initialisierenden Basis-Objekt.
</p>
<p>
Alle anderen Layer dar&#252;ber reichen dann korrekt mit dem geerbten Ctor diese Initialisierung nach Unten.
</p>
</body>
</html>
</richcontent>
</node>
<node CREATED="1512706516628" ID="ID_1092840037" MODIFIED="1512706656273">
<richcontent TYPE="NODE"><html>
<head>
</head>
<body>
<p>
&#252;brigens ist es im IterSource&lt;T&gt;::iterator <i>nicht</i>&#160; notwendig
</p>
</body>
</html>
</richcontent>
<richcontent TYPE="NOTE"><html>
<head>
</head>
<body>
<p>
...das war nur ein unn&#246;tiger Fix nach dem Gie&#223;kannen-Prinzip.
</p>
<p>
</p>
<p>
Denn dieser Iterator soll niemals mit einem Basis-Objekt initialisiert werden,
</p>
<p>
sondern stets von der IterSource-Builder-Funktion konstruiert.
</p>
<p>
Und wenn man selber keinen Ctor in eine Klasse schreibt, sondern nur ctor-erbt,
</p>
<p>
dann werden auch die Copy-Konstruktoren korrekt automatisch generiert.
</p>
</body>
</html>
</richcontent>
<icon BUILTIN="idea"/>
</node>
</node>
<node CREATED="1512621222901" ID="ID_701320194" MODIFIED="1512706102580" TEXT="bad function call">
<icon BUILTIN="button_ok"/>
<node CREATED="1512621654283" ID="ID_1975194377" MODIFIED="1512621667489" TEXT="passiert im FIlter-Iterator-Test">
<icon BUILTIN="messagebox_warning"/>
</node>
<node BACKGROUND_COLOR="#fdfdcf" COLOR="#ff0000" CREATED="1512621668449" ID="ID_369576813" MODIFIED="1512621682544" TEXT="hab ich einen schon funktionierenden Test gebrochen?">
<icon BUILTIN="flag-pink"/>
<node CREATED="1512621668449" ID="ID_369576813" MODIFIED="1512705931292" TEXT="hab ich einen schon funktionierenden Test gebrochen?">
<font ITALIC="true" NAME="SansSerif" SIZE="12"/>
<icon BUILTIN="help"/>
</node>
<node CREATED="1512705938426" ID="ID_483656941" MODIFIED="1512706091518" TEXT="nein: der Test-Code war kaputt">
<icon BUILTIN="ksmiletris"/>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1512705974765" ID="ID_1628672101" MODIFIED="1512706019739" TEXT="Vorsicht: der Builder macht move!">
<icon BUILTIN="clanbomber"/>
</node>
<node CREATED="1512706022079" ID="ID_118572066" MODIFIED="1512706045943" TEXT="d.h. die lokale Variable im Test war danach kaputt..."/>
<node CREATED="1512706051907" ID="ID_133885955" MODIFIED="1512706067900" TEXT="in der vorherigen Version fehlte nur irgendwo in der Kette ein move-ctor"/>
<node CREATED="1512706069104" ID="ID_596682451" MODIFIED="1512706085953" TEXT="und deshalb ist nicht aufgefallen, da&#xdf; das Objekt schon tot war"/>
</node>
</node>
</node>
@ -6364,7 +6493,7 @@
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1512620997827" ID="ID_173233581" MODIFIED="1512621372921" TEXT="erzeugte source erneut verpacken">
<icon BUILTIN="flag-yellow"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1512621101645" ID="ID_1982135306" MODIFIED="1512621376089" TEXT="polymorphie: verschiedene Pipelines">
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1512621101645" ID="ID_1982135306" MODIFIED="1512706679017" TEXT="Polymorphie: verschiedene Pipelines">
<richcontent TYPE="NOTE"><html>
<head>